V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
flyfowl
V2EX  ›  程序员

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

  •  
  •   flyfowl · Nov 9, 2017 · 1672 views
    This topic created in 3096 days ago, the information mentioned may be changed or developed.

    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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2564 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 07:47 · PVG 15:47 · LAX 00:47 · JFK 03:47
    ♥ Do have faith in what you're doing.