2013-02-25 47 views
4

我成功运行sudo apt-get install libncurses5-dev大厦的HelloWorld C++程序在Linux中的ncurses

在我的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; 
} 

我收到以下错误:

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 

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

+0

你使用的是ubuntu吗? – mathematician1975 2013-02-25 22:51:56

+2

你的选择是错误的顺序 - '-L'必须在'-l'之前,并且都必须是'.o' – 2013-02-25 23:14:13

+0

而你想要一个64位系统上的32位程序(为什么?),所以你可能需要'lib32ncurses5-dev'软件包 – 2013-02-26 06:50:18

回答

3
g++ HelloWorld.cpp -lncurses -o HelloWolrd 

如果你有一个32位机,gcc compile m32 auto。如果你有一个64位的机器,并且你想编译32位,你可以使用