无法编译使用 ncurses 的 C/C++ 代码 [重复]

2023-12-21

我刚刚发现 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;
}

为什么我会收到此错误。更重要的是,我该如何解决这个问题?


你必须链接 ncurses 库

g++ -o hello_world hello_world.cpp -lncurses
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法编译使用 ncurses 的 C/C++ 代码 [重复] 的相关文章

随机推荐