编译链接库时出现“未定义的引用”错误。

4

我向我的代码中添加了一个第三方库,在运行make时出现了以下错误。请帮助我理解这个错误。

(.text+0x9b4): undefined reference to `snd_strerror'
/home/bet/Tent/tun/app/Common/hl/lib/libGHAL.a(gfxhal.o): In function `GFX_create_region':
/home/bet/Tent/tun/app/Common/hl/src/GHAL/gfxhal.c:1141: undefined reference to `my_key_handler'
/home/bet/Tent/tun/app/Common/hal/src/GHAL/gfxhal.c:1141: undefined reference to `create_window'
collect2: ld returned 1 exit status
make[2]: *** [all] Error 1
make[2]: Leaving directory `/home/bet/Tent/tun/app/Common/c_app'
make[1]: *** [ctv_all] Error 2
make[1]: Leaving directory `/home/bet/Tent/tun/app/Common'

这个第三方库是否提供了添加正确链接标志的机制?使用pkg-config吗? - gcbenison
2个回答

7
那是链接错误,告诉你链接器找不到你正在使用的库的定义。
你需要将库链接到你的项目中。
gcc <your files for compilation> -lLibName

阅读此文以更好地理解。


假设库和包含文件已安装在“标准”位置,工具链将在这些位置查找它们。 - ArjunShankar
链接已失效(在此评论的历史记录中)。 - NAND

0

即使已安装readline库并将-lreadline添加到gcc编译命令中,我仍然遇到错误。

  1. readline库已安装
  2. -lreadline已添加到gcc编译命令中。

我的问题根本原因是库/代码的顺序:-lreadline(和其他库)应该放在-o选项之前。


1
这并没有回答原问题。你最好提出一个新问题,提供所有相关细节(参见如何提问以获取有关提出良好问题的提示)。 - cybernetic.nomad

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接