动态库使用静态库,未定义符号出现 [英] Dynamic library uses statics libraries, undefined symbols appears

查看:1856
本文介绍了动态库使用静态库,未定义符号出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经寻找一个解决方案,我的麻烦和刚刚获得一些线索,但我找不到任何一致的解决方案:
我有一个动态库(libdyna.so)的code,使用的3静态库(libone.a,libtwo.a,libthree.a)和log4cpp库中的函数。
当我建造它的第一次一切看起来都很好,我可以使libdyna.so',但是当y与我的Java测试程序虽然封装测试它(JNI封装正常工作)我得到了很多未定义的引用。

I've look for a solutions to my trouble and just get some clues, but I could not find any consistent solution: I have the code of a dynamic library (libdyna.so), that uses the functions of 3 statics libraries (libone.a, libtwo.a, libthree.a) and the log4cpp library. And when I built it the first time everything looked fine, I could make the 'libdyna.so', but when y tested it with my java test program though a wrapper (the jni wrapper works fine) I got lots of undefined references.

然后我把-z DEFS标志make文件和大量未定义的引用的出现,我不能重新编译的动态库。

Then I put the "-z defs" flag to the make file and a lot of undefined references appear and I could not compile the dynamic library again.

我做了'纳米'命令与三个静态库,并将其导出所有我在DYNA lib中正确使用的功能。但是,当我在'libdyna.so,一个包括3个静态库制作纳米,我发现未定义的符号(函数)。

I've made the 'nm' command with the three statics libraries and it exports all the functions that I use in the dyna lib correctly. But when I made nm over the 'libdyna.so', the one which includes the 3 statics libs, I found Undefined symbols (functions).

我认为解决方案必须像添加一些标志连接器的东西时,我想提出的动态的,但我真的不知道。
谁能帮助我,或者告诉我一些想法?如果需要一些code,请让我知道,我会在这里粘贴。
非常感谢。

I think that the solutions must be something like adding some flag to the linker when I want to made the dynamic one, but i really don't know. Could anyone help me, or tell me some ideas?. if some code is needed please let me know and I'll paste it here. Thanks a lot.

P / D:对不起,我的英语不好

P/D: Sorry for my bad english.

推荐答案

您可以使用链接器选项 - 全归档,它将包括整个静态库并可能解决您的问题,虽然图书馆可以成为相当大的。

You could use linker option --whole-archive, it will include whole static libraries and will probably solve your problem, although the library could become quite big.

g++ -shared -o libdyna.so dyna.o -Wl,-whole-archive -la -lb -lc -Wl,-no-whole-archive

男人LD:

对于--whole存档选项后,在命令行中提到的每个存档,包括在归档中的每个对象文件
             链接,而不是搜索存档所需的目标文件。这通常用来将存档文件到共享
             库,迫使每个对象被包括在所产生的共享库中。

For each archive mentioned on the command line after the --whole-archive option, include every object file in the archive in the link, rather than searching the archive for the required object files. This is normally used to turn an archive file into a shared library, forcing every object to be included in the resulting shared library.

不要忘了关闭轮候册,-no-全归档

检查也出现在GCC命令行库的顺序,以确保它们是动态库的目标文件后,否则连接器将不会加载它们。如果libone使用libtwo例如,它也是重要的libone到libtwo之前出现。这可能是你的问题的替代解决方案。

Check also the order of appearing of the libraries in gcc command line, make sure they are after the object files of the dynamic library, otherwise the linker will not load them. If libone uses libtwo for example, it's also important for libone to appear before libtwo. It could be alternative solution for your problem.

这篇关于动态库使用静态库,未定义符号出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆