【问题标题】:Issue with makefile on UbuntuUbuntu上的makefile问题
【发布时间】:2015-12-30 22:32:43
【问题描述】:

我正在尝试安装一个包含一些 C 文件的文件夹的程序。我运行 makefile 但我收到以下错误:

/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1128: undefined reference to `tgoto'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1129: undefined reference to `tputs'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1138: undefined reference to `tputs'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1145: undefined reference to `tputs'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1154: undefined reference to `tputs'
readline/libreadline.a(display.o): In function `delete_chars':
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1182: undefined reference to `tgoto'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1183: undefined reference to `tputs'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1189: undefined reference to `tputs'
readline/libreadline.a(signals.o): In function `cr':
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/signals.c:301: undefined reference to `tputs'
collect2: error: ld returned 1 exit status

你知道我该如何解决吗? (在 Ubuntu 上)

【问题讨论】:

  • 您是否安装了curses 库?程序是否包含configure 脚本?
  • @EugeneSh。我使用 ./configure 来获取 makefile。如何安装 curses 库?
  • sudo apt-get install libncurses5-dev。并阅读您的程序的文档(如果有的话)以了解其他依赖项。
  • 你应该链接一些库。使用这些参数编译-ltermcap -lncurses
  • 好吧,如果它通过了configure,那么所需的库应该没问题。除非它警告你。

标签: c ubuntu makefile


【解决方案1】:

你在c程序中使用过tputs,所以你必须使用#include <curses.h>#include <term.h>。未定义的引用是链接器错误。在编译 c 程序时的 Makefile 中,您应该链接 -lcurses-lncurses。将类似的行添加到您的 Makefile。使用适当的链接库进行编译。

例如

gcc file.c -o output_file -lcurses -ltermcap

gcc file.c -o output_file -lcurses -ltermcap

【讨论】:

  • 除了-lncurses 之外,我还必须添加-ltermcap 才能解决tputs 参考问题。
猜你喜欢
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多