* Is it possible to use RTTI in a dynamic library ?
@ 2003-11-17 16:08 JOLY Loic
2003-11-17 16:26 ` Nathan Sidwell
2003-11-17 16:27 ` Eljay Love-Jensen
0 siblings, 2 replies; 3+ messages in thread
From: JOLY Loic @ 2003-11-17 16:08 UTC (permalink / raw)
To: gcc-help
The problem is under a Linux platform with gcc-3.2.2.
We've got an header containing the following (simplified):
class A
{
public:
virtual bool fred1();
};
class B : public A
{
public:
virtual bool fred2();
};
Included in a .so file (a dll in Windows terms)
and Included in an application
The .so file is loaded in a dynamic way: dlopen, dlsym, dlclose
(LoadLibrary, GetProcAddress) and returns pointers to A objects.
What we want to do in the main application:
A *a = getFromSoFile(); // I'm sure this is a pointer to B in the real life
B *b = dynamic_cast<B *>(a);
--> The result is b == NULL;
Of course typeid(a) != typeid(B *)
but the strings returned by typeid(a).name() and typeid(B *).name() are
equal.
Is there any way to make to make it work ? If we put everything directly
in the program (no .SO file) it works as intended.
--
Loïc
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Is it possible to use RTTI in a dynamic library ?
2003-11-17 16:08 Is it possible to use RTTI in a dynamic library ? JOLY Loic
@ 2003-11-17 16:26 ` Nathan Sidwell
2003-11-17 16:27 ` Eljay Love-Jensen
1 sibling, 0 replies; 3+ messages in thread
From: Nathan Sidwell @ 2003-11-17 16:26 UTC (permalink / raw)
To: JOLY Loic; +Cc: gcc-help
JOLY Loic wrote:
> The problem is under a Linux platform with gcc-3.2.2.
> We've got an header containing the following (simplified):
> The .so file is loaded in a dynamic way: dlopen, dlsym, dlclose
> (LoadLibrary, GetProcAddress) and returns pointers to A objects.
>
> Is there any way to make to make it work ? If we put everything directly
> in the program (no .SO file) it works as intended.
http://gcc.gnu.org/faq.html#dso
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Is it possible to use RTTI in a dynamic library ?
2003-11-17 16:08 Is it possible to use RTTI in a dynamic library ? JOLY Loic
2003-11-17 16:26 ` Nathan Sidwell
@ 2003-11-17 16:27 ` Eljay Love-Jensen
1 sibling, 0 replies; 3+ messages in thread
From: Eljay Love-Jensen @ 2003-11-17 16:27 UTC (permalink / raw)
To: JOLY Loic, gcc-help
Hi Loïc,
The RTTI mechanism used by dynamic_cast relies upon the address of the type information structure. It appears that the DSO has a different type information structure for the object than the one being used in the dynamic_cast. Not good.
What are the compiler/linker flags being used to make the .so?
Does -fweak make a difference?
If you are using -Bsymbolic ... don't use that.
Consider doing a reinterpret_cast<B*>, since you are sure that it is a pointer to B in real life.
Consider changing getFromSoFile() to return a B* instead of an A*.
--Eljay
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-11-17 16:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-17 16:08 Is it possible to use RTTI in a dynamic library ? JOLY Loic
2003-11-17 16:26 ` Nathan Sidwell
2003-11-17 16:27 ` Eljay Love-Jensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).