V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
flyfowl
V2EX  ›  程序员

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

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

    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   ·   实用小工具   ·   5333 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 06:56 · PVG 14:56 · LAX 23:56 · JFK 02:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.