如何解决未解析的符号?
问候。
我在将我的库动态链接到我的程序时遇到问题。 正在发生的事情是这样的:我正在开发一个模块化程序并测试模块系统。问题是我的模块使用了主二进制文件中定义的一些类:一些抽象类,不会引起任何问题,以及一个非常具体的类,它无法解析。
我正在使用 dlopen / dlsym / dlclose 函数集。 我使用 g++ 进行编译。
问题是:如果我要求 dlopen 加载所有符号,那么它无法告诉我“未定义符号:_ZNK3zia3api8DataTreecvRKSsEv
但是,如果我以惰性模式启动 dlopen,它只会在第一次使用所谓的类时发生(并在那之后立即崩溃)。
这就是“DataTree”类,我想让它可用于主二进制文件和模块。 我已经尝试在每个二进制文件中编译它:正如我所料,它不起作用。 我也尝试使其完全内联,但它与我的其他尝试一样无用。 我尝试使用选项“-rdynamic”编译主二进制文件。没有变化。
从昨天开始我一直在寻找、询问朋友,但似乎没有人知道如何解决此类问题。
我使用选项 -fPIC 编译模块的对象,如下所示:
g++ -Wall -fPIC -c mysource.cpp
然后我使用这一行来创建库:
g++ -shared -Wl,-soname,mylib.so.1 -o mylib.so mysource.o
我想最好的解决方案是不编译库中的对象,而是使符号可从主要二进制文件。 那么问题是:如何做到这一点? (这是我必须做的吗?)
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 ?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将
-rdynamic
添加到库模块而不是主程序中,并确保所有具有虚拟方法并继承的类都具有虚拟析构函数。另一个建议:制作一个最小的示例并将其发布在这里。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.