I have a C++ class whose definition is going to be loaded at run-time through dlopen
. I can't get it to link though. I get errors saying there is an "undefined reference to typeinfo".
The relevant part of the code looks like this:
class Interface { ... };
class Impl : public Interface { ... };
Interface *Create() { ... }
// Load shared object around here
Impl *impl = dynamic_cast<Impl*>(Create()); // Undefined reference to typeinfo
I tried adding -rdynamic
to my linker command, but this didn't seem to change anything. Is there something I can do about this?
Since I saw many questions about the same error message caused by undefined virtual functions, I should mention that I'm sure this is not my problem.
Also I should add that I'm sure this is related to dynamic_cast, because if I replace the dynamic_cast with a normal (Impl*)
cast the code links correctly.
dlopen
anddlsym
code. – Radiogramdlopen
. If you're getting errors when you're invokingld
(throughg++
), then we'll need to know what options you've used there and to compile. – Headpin-Wl,-Bstatic -Wl,-Bdynamic
along with a few -l options for libraries. I created a minimal test case which I'm compiling/linking with a simpleg++ foo.cc
and it still causes the same error. – Oersted