g ++虽然安装了

时间:2016-09-16 00:16:07

标签: c++ gcc ncurses

我第一次尝试在ncurses中试验,但是我在编译源代码时遇到了问题。据我所知,ncurses安装在正确的目录中。

我的makefile非常简单:

.cpp :
    g++ -Wall -g -o $* $*.cpp -std=c++11 -lncurses

这是我尝试locate ncurses.h

时的输出
$ locate ncurses.h
/usr/include/ncursesw/ncurses.h

当我检查它是否已安装时

$ dpkg -l | grep ncurses
ii  libncurses5:amd64                                     5.9+20140118-1ubuntu1                               amd64        shared libraries for terminal handling
ii  libncursesw5:amd64                                    5.9+20140118-1ubuntu1                               amd64        shared libraries for terminal handling (wide character support)
ii  libncursesw5-dev:amd64                                5.9+20140118-1ubuntu1                               amd64        developer's libraries for ncursesw
ii  mtr-tiny                                              0.85-2                                              amd64        Full screen ncurses traceroute tool
ii  ncurses-base                                          5.9+20140118-1ubuntu1                               all          basic terminal type definitions
ii  ncurses-bin                                           5.9+20140118-1ubuntu1                               amd64        terminal-related programs and man pages
ii  ncurses-term                                          5.9+20140118-1ubuntu1                               all          additional terminal type definitions

但是当我尝试制作

时,g ++会告诉我这个
bankacct.cpp:18:29: fatal error: ncurses.h: No such file or directory
compilation terminated.

不幸的是,我没有root权限,我需要能够在这台机器上编译。我有什么选择?

我根据其他用户的建议尝试包含<ncursesw/ncurses.h>,但现在g ++给了我这个错误:

$ make bankacct
g++ -Wall -g -o bankacct bankacct.cpp -std=c++11 -lncurses
/usr/bin/ld: cannot find -lncurses

如果我尝试删除-lncurses,它会给我这个:

$ make bankacct
g++ -Wall -g -o bankacct bankacct.cpp -std=c++11
/tmp/cc8rPQfK.o: In function `main':
bankacct.cpp:23: undefined reference to `initscr'

现在我尝试连接这些库。这就是我的所作所为:

$ locate libncurse
/lib/x86_64-linux-gnu/libncurses.so.5
/lib/x86_64-linux-gnu/libncurses.so.5.9
/lib/x86_64-linux-gnu/libncursesw.so.5
/lib/x86_64-linux-gnu/libncursesw.so.5.9
/usr/lib/x86_64-linux-gnu/libncurses++w.a
/usr/lib/x86_64-linux-gnu/libncursesw.a
/usr/lib/x86_64-linux-gnu/libncursesw.so
/usr/share/doc/libncurses5
/usr/share/doc/libncursesw5
/usr/share/doc/libncursesw5-dev
/var/lib/dpkg/info/libncurses5:amd64.list
/var/lib/dpkg/info/libncurses5:amd64.md5sums
/var/lib/dpkg/info/libncurses5:amd64.postinst
/var/lib/dpkg/info/libncurses5:amd64.postrm
/var/lib/dpkg/info/libncurses5:amd64.shlibs
/var/lib/dpkg/info/libncurses5:amd64.symbols
/var/lib/dpkg/info/libncursesw5-dev:amd64.list
/var/lib/dpkg/info/libncursesw5-dev:amd64.md5sums
/var/lib/dpkg/info/libncursesw5-dev:amd64.postinst
/var/lib/dpkg/info/libncursesw5:amd64.list
/var/lib/dpkg/info/libncursesw5:amd64.md5sums
/var/lib/dpkg/info/libncursesw5:amd64.postinst
/var/lib/dpkg/info/libncursesw5:amd64.postrm
/var/lib/dpkg/info/libncursesw5:amd64.shlibs
/var/lib/dpkg/info/libncursesw5:amd64.symbols

然后我尝试了我的makefile的两个变体:

g++ -Wall -g -L/usr/lib/x86_64-linux-gnu/ -o $* $*.cpp -std=c++11 -lncurses

g++ -Wall -g -L/lib/x86_64-linux-gnu/ -o $* $*.cpp -std=c++11 -lncurses

仍然给我错误undefined reference to 'initscr'(没有-lncurses)或/usr/bin/ld: cannot find -lncurses(带有它)

1 个答案:

答案 0 :(得分:4)

-lncurses

告诉链接器查找名为&#34; ncurses的库。&#34;。你清楚地表明你的图书馆不是你的名字:

/usr/lib/x86_64-linux-gnu/libncursesw.a

你需要

-lncursesw

您不需要修改源代码以指定<ncursesw/ncurses.h>您只需添加

-I/usr/include/ncursesw