引用库函数, CentOS 没问题, Ubuntu 编译报错“undefined reference to”

2017-11-09 14:24:42 +08:00
 flyfowl

CentOS 上的 gcc 版本:gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)

Ubuntu 上的 gcc 版本:gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)

CentOS 正常编译过,Ubuntu 报错,纠结了一天,原来是 gcc 版本不一样导致 linker 查找链接函数方式不同,贴上来帮助遇到同样问题的 coder

The trick here is to put the library AFTER the module you are compiling. The problem is a reference thing. The linker resolves references in order, so when the library is BEFORE the module being compiled, the linker gets confused and does not think that any of the functions in the library are needed. By putting the library AFTER the module, the references to the library in the module are resolved by the linker.

感谢: https://stackoverflow.com/questions/1517138/trying-to-include-a-library-but-keep-getting-undefined-reference-to-messages

1480 次点击
所在节点    程序员
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/404945

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX