尽管安装了g ++,但找不到ncurses.h [英] g++ can't find ncurses.h despite it being installed
问题描述
我第一次尝试在ncurses中进行试验,但是在编译源代码时遇到了问题.据我所知,ncurses已安装在正确的目录中.
I'm trying to experiment around in ncurses for the first time, but I'm having problems compiling my source code. As far as I can tell, ncurses is installed and in the proper directories.
我的makefile非常简单:
My makefile is super simple:
.cpp :
g++ -Wall -g -o $* $*.cpp -std=c++11 -lncurses
这是我尝试locate ncurses.h
$ locate ncurses.h
/usr/include/ncursesw/ncurses.h
以及当我检查是否已安装
and when I check to see if it's installed
$ 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 ++告诉了我
But g++ tells me this when I try to make
bankacct.cpp:18:29: fatal error: ncurses.h: No such file or directory
compilation terminated.
不幸的是,我没有root访问权限,我需要能够在此计算机上进行编译.我有什么选择?
Unfortunately, I've not got root access and I need to be able to compile on this machine. What are my options?
我已经尝试根据其他用户的建议添加<ncursesw/ncurses.h>
,但是现在g ++给了我这个错误:
I've tried including <ncursesw/ncurses.h>
based on suggestions from other users, but now g++ is giving me this error:
$ make bankacct
g++ -Wall -g -o bankacct bankacct.cpp -std=c++11 -lncurses
/usr/bin/ld: cannot find -lncurses
,如果我尝试删除-lncurses
,它会给我这样的信息:
and if I try removing -lncurses
it gives me this:
$ 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'
现在,我尝试链接库.这是我所做的:
Now I've tried linking the libraries. Here's what I did:
$ 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的两个变体:
So then I tried two variations of my 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
(带有它)
which still gave me the errors undefined reference to 'initscr'
(without -lncurses
) or /usr/bin/ld: cannot find -lncurses
(with it)
推荐答案
-lncurses
告诉链接器寻找一个名为"ncurses"的库.您清楚地表明这不是您的图书馆所称的:
tells the linker to look for a library called "ncurses.". You clearly indicate that's not what your library is called:
/usr/lib/x86_64-linux-gnu/libncursesw.a
您需要
-lncursesw
您无需修改源代码即可指定<ncursesw/ncurses.h>
您可以简单地添加
You don't need to modify the source code to specify <ncursesw/ncurses.h>
you can simply add
-I/usr/include/ncursesw
这篇关于尽管安装了g ++,但找不到ncurses.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!