On Nov 14, 2008, at 9:47 AM, edam wrote:
Hi there,
I was wondering if anyone could shed some light on a problem I'm
having.
I can't seem to get dynamic_cast() to downcast an object returned
from a
library loaded with dlopen(). I was wondering if this is expected
behaviour or a bug I'm seeing? From what I've read on the web, I think
it *should* work.
Some code will illustrate the problem. The code included below can be
compiled with the following commands:
g++ -g -o test test.cpp -ldl
g++ --shared -fPIC -g -o lib.so lib.cpp
When you run 'test', you would expect the downcasts in create() and
main() to work, but only the one in the library does. For example,
when
I run 'test', I get the following:
1st dynamic_cast() returns: 0x13b8670
2nd dynamic_cast() returns: 0
Does anyone know why this is?
This looks similar to what I was experiencing...
The solution to my problem was to 'or' the mode with RTLD_GLOBAL.
Have you tried that?