我刚刚发现了ncurses,并开始学习它,但是我的教程中的示例在我的计算机上无法编译。
我不得不手动安装ncurses,通过输入“apt-get install libncurses5-dev libncursesw5-dev”来完成。我之所以这样做是因为在此之前,我遇到了一个错误,指出我无法“#include ”。
安装它确实起作用了,但现在我却得到了另一个错误:
touzen@comp:~/learning_ncurses$ g++ -o hello_world hello_world.cpp
/tmp/ccubZbvK.o: In function `main':
hello_world.cpp:(.text+0xa): undefined reference to `initscr'
hello_world.cpp:(.text+0x16): undefined reference to `printw'
hello_world.cpp:(.text+0x1b): undefined reference to `refresh'
hello_world.cpp:(.text+0x20): undefined reference to `stdscr'
hello_world.cpp:(.text+0x28): undefined reference to `wgetch'
hello_world.cpp:(.text+0x2d): undefined reference to `endwin'
collect2: ld returned 1 exit status
我编译的代码长这样:
#include <ncurses.h>
int main(){
initscr();
printw("Hai thar world...");
refresh();
getch();
endwin();
return 0;
}
我为什么会得到这个错误?更重要的是,我该如何修复它?
libc
(除非你使用-ffreestanding告诉它不要这样做)。 - Karoly Horvathg++ -lncurses helloworld.cpp
,这导致了与楼主相同的错误。所以我的问题是我需要解释说明-lncurses
必须在编译命令的末尾。 - aesede