【发布时间】:2021-07-05 06:27:14
【问题描述】:
我想在 C 中实现一个循环,该循环在按下特定键时停止。为此,我一直在尝试使用 ncurses 库。我有一个离线的 Redhat 系统,无法连接到互联网。运行命令locate libncurses 后,我得到许多行,例如/usr/lib64/libncurses++.so.5。我认为这意味着我的系统上存在 ncurses 库。接下来我尝试运行以下代码来测试 ncurses
#include <ncurses.h>
int
main()
{
initscr();
cbreak();
noecho();
scrollok(stdscr, TRUE);
nodelay(stdscr, TRUE);
while (true) {
if (getch() == 'g') {
printw("You pressed G\n");
}
napms(500);
printw("Running\n");
}
}
这取自问题Using kbhit() and getch() on Linux
当我尝试以以下方式运行时 gcc -o testncurses testncurse.c 我收到错误 undefined reference to 'initscr'。然后我继续以gcc -o testncurses testncurse.c -lncurses 运行它。但我得到了错误
/usr/bin/ld: cannot find -lncurses
collect2:error: ld returned 1 exit status
我应该怎么做才能运行上面的代码?
我也尝试安装一个较新的 ncurses 库包,但这给了我一个错误,说正在安装的包中的文件与已安装的包冲突。
【问题讨论】:
-
你有安装ncurses的开发包吗?
-
正如我所说,在尝试安装它们时,我收到包与已安装的包冲突的错误
-
你需要ncurses的开发包。如果你不能安装它,你可能不走运。所以,你应该解决安装冲突而不是忽略它。
标签: compilation linker ncurses