g++ not using curses library even with -lcurses

Aug 4, 2014 at 11:59pm
I am trying to compile some code that uses curses to clear the screen, on my personal machine (Debian sid) it works, but in Cygwin and a Ubuntu 14.04 VM it doesn't compile. I have tried using both -lcurses and -lncurses, and I'm including ncurses.h in the program, even with these, it gives me the following error:

1
2
3
4
5
6
7
  g++ -std=c++11 -g -Wall -lncurses -fpermissive -O2 main.o turn.o clearscreen.o endcheck.o parse.o randevents.o -o CWS

clearscreen.o: In function `clearScreen()':
/home/czar/Downloads/CWS/clearscreen.cpp:9: undefined reference to `cur_term'
/home/czar/Downloads/CWS/clearscreen.cpp:18: undefined reference to `tigetstr'
/home/czar/Downloads/CWS/clearscreen.cpp:18: undefined reference to `putp'
/home/czar/Downloads/CWS/clearscreen.cpp:12: undefined reference to `setupterm' 
Aug 5, 2014 at 8:55pm
Bumping, sorry if this is too soon, I don't know how many pages people will go to here.
Aug 7, 2014 at 8:44pm
Last bump
Aug 7, 2014 at 8:53pm
Do you have curses installed on the Ubuntu machine?
Aug 7, 2014 at 9:04pm
Try putting -lncurses last.
Aug 8, 2014 at 12:37am
Er, put it first for GCC.

You must apt-get install ncurses-dev (or whatever the package is called) before you can use NCurses.

Hope this helps.
Aug 8, 2014 at 1:01am
cmiiw, I think that the order matters if you are using an static library, and in that case the one that needs the symbols should appear before the one that defines them.
Aug 8, 2014 at 2:44am
@Duoas, You'll get a 'file not found' error if you link to something that isn't there.

My guess is that there are flags you need on those other machines, try:
$ pkg-config --libs ncurses

If it outputs something other than -lncurses ( and works too ), then make your compile line:

g++ -std=c++11 -g -Wall `pkg-config --libs ncurses` -fpermissive -O2 main.o turn.o clearscreen.o endcheck.o parse.o randevents.o -o CWS

Note that those are back ticks, not single quotes.
Topic archived. No new replies allowed.