Re: Strange dynamic_cast problem
Re: Strange dynamic_cast problem
- Subject: Re: Strange dynamic_cast problem
- From: Eric Gorr <email@hidden>
- Date: Thu, 6 Nov 2008 10:06:19 -0500
Chris Suter wrote:
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.
Ah, thank you for your explanation. This is starting to make more
sense to me.
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.
Sadly, the above is not a reliable solution. Once I tried to take it
into the real case, it failed.
Well, if anyone has any suggestions on how to make the dynamic linker
coalesce symbols I'm manually loading at runtime, I would be quite
interested.
_______________________________________________
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