简体   繁体   English

使用静态库编译的共享库中的未定义符号

[英]Undefined symbols in a shared library compiled with a static library

I have a problem with linking together different libraries using it in one executable project. 我在一个可执行项目中将使用它的不同库链接在一起时遇到问题。

Let's say Project A contains a function named foo() ; 假设项目A包含一个名为foo()的函数; It is compiled as a static library. 它被编译为静态库。
Project B contains a function named bar() , includes a header from A and compiled as a shared library with -Wl , --whole-archive libA.a -Wl , --no-whole-archive flags . 项目B包含一个函数名为bar() ,包括来自A的报头和编译为一个共享库-Wl--whole-archive libA.a -Wl--no-whole-archive flags
libB.so was moved to /usr/lib . libB.so已移至/usr/lib

Now, project C includes Bh , calls bar() , but wasn't compiled due to the reason of undefined reference to foo() function, which was defined in project A. 现在,项目C包含Bh ,调用bar() ,但是由于未定义对foo()函数的引用而未进行编译,而foo()函数是在项目A中定义的。

nm libB.so says: nm libB.so说:

U foo

I am using gcc, the programming language is C, the IDE is Eclipse CDT. 我正在使用gcc,编程语言是C,IDE是Eclipse CDT。

Is anyone who has an idea or tip to solve this problem? 有谁有解决这个问题的想法或建议吗?

Thank you. 谢谢。

Thanks to Icarus3 for his contribution, the problem is restricted. 感谢Icarus3的贡献,这个问题得到了解决。

Some functions in ProjectA used restrict keyword, thus it was compiled with -std=gnu99. ProjectA中的某些功能使用了strict关键字,因此使用-std = gnu99进行了编译。 It turns out that eliminating this keyword from the code and the -std=gnu99 from the compiling command eventually solved the problem. 事实证明,从代码中删除该关键字,从编译命令中删除-std = gnu99最终解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM