使用 ncurses 在 Linux 中构建 HelloWorld C++ 程序

use*_*105 6 linux ncurses

我成功跑了 sudo apt-get install libncurses5-dev

在我的 Eclipse 窗口中,我尝试构建以下HelloWord.cpp程序:

#include <ncurses.h>

int main()
{
    initscr();                 /* Start curses mode     */
    printw("Hello World !!!"); /* Print Hello World    */
    refresh();                 /* Print it on to the real screen */
    getch();                   /* Wait for user input */
    endwin();                  /* End curses mode    */

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Invoking: GCC C++ Linker
g++ -m32 -lncurses -L/opt/lib -o "Test_V"  ./src/curseTest.o ./src/trajectory.o ./src/xJus-epos.o   -lEposCmd
/usr/bin/ld: cannot find -lncurses
collect2: error: ld returned 1 exit status
make: *** [Test_V] Error 1
Run Code Online (Sandbox Code Playgroud)

看起来编译器正在搜索 ncurses 库并找不到它?我检查过/usr/lib,那里不存在该库,所以我需要手动链接 ncurses 库那里 - 我认为 get-apt 安装程序会自动执行此操作吗?

小智 9

g++ HelloWorld.cpp -lncurses -o HelloWolrd
Run Code Online (Sandbox Code Playgroud)

如果你有一台 32 位机器,gcc compile m32 auto. 如果你有一台 64 位机器并且你想编译 32 位你