• 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: Strange dynamic_cast problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange dynamic_cast problem


  • Subject: Re: Strange dynamic_cast problem
  • From: "Chris Suter" <email@hidden>
  • Date: Wed, 5 Nov 2008 11:22:18 +1100

On Wed, Nov 5, 2008 at 2:26 AM, Eric Gorr <email@hidden> wrote:

> Thank you again for your comments.
>
> I've been looking into the issue a bit more and thought that if it were
> possible to make the destructors pure virtual functions as well, then that
> would solve the problem.
>
> Googling for "pure virtual destructors c++", I came across:
>
> http://www.linuxtopia.org/online_books/programming_books/thinking_in_c++/Chapter15_024.html
>
> While it seems strange, apparently this is allowed in C++.
>
> So, if I changed Shared.h to look like:
>
> *****
> *****
> #define VISIBLE __attribute__ ((visibility("default")))
>
> class VISIBLE A
> {
> public:
>    virtual ~A( void )          = 0;
>    virtual void Func( void )   = 0;
> };
> A::~A() {}
>
> class VISIBLE B : public A
> {
> public:
>    virtual ~B( void )          = 0;
>    virtual void Func1( void )  = 0;
> };
> B::~B() {}
>
> extern "C" VISIBLE A *GetA( void );
> *****
> *****
>
> everything worked in all three cases.
>
>
> And comments on this solution? Any reason why this wouldn't be perfectly
> valid?

Here's what's happening: the symbols get marked as weak and so they
will get coalesced when linked (either by the static linker or the
dynamic linker). However, the dynamic linker won't coalesce symbols
between two libraries that you load—it will only coalesce symbols
between the object you're loading it from and the object you're
loading (there might be some way of changing this behaviour). That's
why it was failing when your LibraryLoader had no references to B. As
soon as you make any reference to B in LibraryLoader, you'll force a
symbol to be created and that's all that you've done this time: by
defining the destructor outside of the class, you're forcing it to be
included in LibraryLoader.

Now I don't know if the compiler is guaranteed to always emit a
reference to B for the pattern you've used so I'd either check that,
use one of the solutions I suggested, use a more certain way of
ensuring that B's symbols are included in LibraryLoader, or figure out
a way to make the dynamic linker coalesce symbols in libraries you're
loading.

-- Chris
 _______________________________________________
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

References: 
 >Strange dynamic_cast problem (From: Eric Gorr <email@hidden>)
 >Re: Strange dynamic_cast problem (From: "Chris Suter" <email@hidden>)
 >Re: Strange dynamic_cast problem (From: Eric Gorr <email@hidden>)
 >Re: Strange dynamic_cast problem (From: Eric Gorr <email@hidden>)

  • Prev by Date: Re: Undefined symbols: "_fputs$UNIX2003", referenced from:
  • Next by Date: Re: Regular Expression in Xcode Editor: newlines+whitespace
  • Previous by thread: Re: Strange dynamic_cast problem
  • Next by thread: Re: Strange dynamic_cast problem
  • Index(es):
    • Date
    • Thread