How to resolve an unresolved symbol?
Greetings.
I'm having a problem dynamically linking my lib to my program. Here's what's happening : I'm developing a modular program and testing the module system. The thing is my modules uses some class that are defined in the main binary : some abstract classes, which don't cause any issues, and a very concrete class, which just can't be resolved.
I'm using the dlopen / dlsym / dlclose set of functions. And I compile using g++.
The thing is : if I ask dlopen to load all the symbols, then it fails telling me "undefined symbol: _ZNK3zia3api8DataTreecvRKSsEv
But if I launch dlopen in lazy mode, it will only happen at the first usage of the so-called class (and crash right after that).
So this is the "DataTree" class, and I want to make it available for both the main binary and the modules. I already tried to compile it in each of the binaries : as I expected, it didn't work. I also tried to make it entirely inline, but it's as useless as my other attempt. I tried to compile the main binary with the option "-rdynamic". No changes.
I've been searching, asking to friends since yesterday but nobody seems to know how to solve this kind of problems.
I compile the objects of the module with the option -fPIC, like this :
g++ -Wall -fPIC -c mysource.cpp
And then I use this line to make the library :
g++ -shared -Wl,-soname,mylib.so.1 -o mylib.so mysource.o
I suppose the best solution would be to not compile the object within 开发者_运维问答the library, but to make the symbol available from the main binary. So the question is : how to do so ? (and is it what I must do ?)
Try adding -rdynamic
to the library module not the main program, and ensure that all your classes which have virtual methods and are inherited have a virtual destructor. Another suggestion: make a minimal example and post it here.
精彩评论