• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: frameworks, dynamic_cast and gcc 4.0
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: frameworks, dynamic_cast and gcc 4.0


  • Subject: Re: frameworks, dynamic_cast and gcc 4.0
  • From: Andreas Grosam <email@hidden>
  • Date: Mon, 22 Aug 2005 16:35:05 +0200


On 22.08.2005, at 14:42, Stephan Huber wrote:

Hi all,

I switched with my code to XCode 2.1 and gcc 4.0. Now most of my dynamic_casts are failing (they worked fine before XCode 2.1). And I don't know why, my knowledge of the inners of the compiler etc is limited.

To be precise: the dynamic_casts are working in the scope of the application, but If I call a method/function inside my custom framework which does a dynamic_cast, this dynamic_cast fails


Firstly, please search this list for similar problems, I already discussed a couple of problems.


Secondly, a few questions:
1) are you using gcc-4.x for ALL your sources?
2) do you use the shared library version of the std C++ lib? (will be *implicitly* linked to your products!)
3) does the app link without link errors?
4) in case of gcc-4, did you "export" the classes in question propperly (look for "symbols visibility").
5) Triple-check, that your are **indeed** linking against the frameworks you intend to!! Often, when starting the program, the dynamic linker may fool you and link against others (old versions?) frameworks (not really, *you* made an error, but it is not that obvious in XCode ).


to 4)
Suppose, you define the class A in a dynamic shared object (DSO) S1.
When you perform the dynamic cast from within another DSO, say S2, then the C++ runtime needs accessible RTTI symbols from class A. You ensure that these symbols are accessible, by telling the compiler to declare the symbols of class X to be "exported" (see, "symbol visibility" compiler options, and as well XCode Build settings). The linker then makes the RTTI symbols accessible from within other DSOs during runtime.



So, normally, if you didn't export the symbols of class A, which was defined in DSO S1, you should get linker errors (undefined symbols) when trying to link DSO S2 against S1. (*normally*)


Sum:
In order to dynamic_cast to work, you *need to* link the calling DSO against the DSO where the class is defined, and you also need to export the symbols of the class. It is *not* sufficient to just include the header of the class.





A possible problem:
There is an issue with dynamic_cast, which i'm uncertain whether this is a bug or not (but I tend to be 90% certain, that this is a bug, but i'm unsure whom to blame for this: linker or compiler, optimization?).


The problem arises if there is more than one instance of the (implicitly created) type info object for the *same* class. It seems that gcc-4 treats equal type info objects having *different addresses* as *not* to be equal.

The question is why and when this might happen inadvertantly.


So firstly, you must not include the *module* where the class is defined, in the calling DSO. This causes that two instances of RTTI symbols will be created, and as a result, dynamic_cast might fail.


Furthermore, with templates there might arise more problems, due to the fact that template functions will be created in the same DSO where they are called, it might happen (may be due to an error in the compiler, but not for sure!) that the type info object will be created in this DSO instead of referencing the already existing one, and thus creating a duplicate.
I´m not sure though, if this will actually happen if you propperly link against the DSO, where the class is defined. Otherwise, you might link without errors, but actually there is one (fake RTTI symbols created, missing original one).



To be more specific:

I declare a class inside my framework

class Foo : public osg::Object {...}

I create some objects inside the application and attach them to other objects (they have a property osg::Object (which is declared in another framework)) After a while I need to process the objects inside my custom framework and there the dynamic_cast to Foo fails.

Please clarify:
Which type of objects do you create in DSO app?
In which DSO(s) is this class and *all their base classes* defined?
How many DSOs are involved (including the app)?
In which DSO is the client class defined? (the class of "other object", which has a member of pointer to osg::Object)?
In which DSO do you invoke the dynamic_cast?



I found the following message in the archives
<http://lists.apple.com/archives/Xcode-users/2005/May/msg00315.html> which describes my problem in a more complicated way,
An interesting link! And the author clearly describes the same issue. ;-)

doing some searches in the archives reveils some posts about similar problems, the solution was to *export* the class-definition, but I can't find any information how to do this, but maybe I'm dumb ;)

Yep, search again. Look for how to export symbols in gcc with the __attribute__ spec.
Then define some handy macros. There is already enough info in this list, go figure.


Andreas

P.S. My code worked very well and reliable under gc 3.x and Panther...

Any help is greatly appreciated,

thanks in advance,
Stephan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: frameworks, dynamic_cast and gcc 4.0
      • From: Stephan Huber <email@hidden>
References: 
 >frameworks, dynamic_cast and gcc 4.0 (From: Stephan Huber <email@hidden>)

  • Prev by Date: Java 1.5 (J2SE) not working with XCode
  • Next by Date: OT: I'm a Spammer!
  • Previous by thread: frameworks, dynamic_cast and gcc 4.0
  • Next by thread: Re: frameworks, dynamic_cast and gcc 4.0
  • Index(es):
    • Date
    • Thread