问题描述
在gcc(g ++)下,我编译了一个静态的 .a (称之为 some_static_lib.a )库。我想将这个 .a 文件链接到另一个动态库(称为 libsomeDyn.so $ c $ )我正在建设。虽然编译了 .so ,但在 .so下没有看到 .a 的内容使用 nm 命令:在 libsomeDyn.so 下的 some_static_lib.a 下没有看到函数。我在做什么错了?
静态库在链接时有特殊的规则。如果对象提供了未解析的符号,则静态库中的对象只会添加到二进制文件中。
在Linux上,您可以使用 - whole-archive 链接器选项:
g ++ -Wl, - 整个归档some_static_lib.a -Wl, - no-whole-archive
Under gcc (g++), I have compiled a static .a (call it some_static_lib.a) library. I want to link (is that the right phrase?) this .a file into another dynamic library (call it libsomeDyn.so) that I'm building. Though the .so compiles, I don't see content of .a under .so using nm command:
I do not see functions under some_static_lib.a under libsomeDyn.so. What am I doing wrong?
Static libraries have special rules when it comes to linking. An object from the static library will only be added to the binary if the object provides an unresolved symbol.
On Linux, you can change that behavior with the --whole-archive linker option:
g++ -Wl,--whole-archive some_static_lib.a -Wl,--no-whole-archive
这篇关于如何将静态库链接到gcc的动态库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!