Otto von Bisquick Otto von Bisquick - 1 month ago 6x
C++ Question

g++ can't find ncurses.h despite it being installed

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.

My makefile is super simple:

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

and here's my output when I try to
locate ncurses.h

$ locate 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

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.

Unfortunately, I've not got root access and I need to be able to compile on this machine. What are my options?

I've tried including
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

and if I try removing
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

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

which still gave me the errors
undefined reference to 'initscr'
) or
/usr/bin/ld: cannot find -lncurses
(with it)


tells the linker to look for a library called "ncurses.". You clearly indicate that's not what your library is called:


You need


You don't need to modify the source code to specify <ncursesw/ncurses.h> you can simply add