V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
flyfowl
V2EX  ›  程序员

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

  •  
  •   flyfowl · 2017-11-09 14:24:42 +08:00 · 1325 次点击
    这是一个创建于 2359 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   984 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 21:01 · PVG 05:01 · LAX 14:01 · JFK 17:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.