Undefined reference to `stdscr' while using ncurses

Fari picture Fari · Mar 3, 2012 · Viewed 30.9k times · Source

I am trying to compile my code in Ubuntu 11.10 and getting these errors and more.So far by googling it I think it is a linking error. Specifically, there have been suggestions to make sure you have the right headers and link the -lncurses library. I have already done that. I'm still getting this error. I also read that may be i should install the libncurses, but I already have it installed.

My MakeFile:
CPP           = g++
CPPFLAGS      = -c -Wall -g
LINK          = g++
LDFLAGS_LINUX = -lpthread -lncurses
LDFLAGS       = $(LDFLAGS_LINUX)
RM            = rm


.SUFFIXES:
.SUFFIXES: .o .cpp

.cpp.o:
    $(CPP) $(CPPFLAGS) $*.cpp -o $(SRC_DIR)$*.o

all: skygrid

skygrid: skygrid.o commServer.o pose.o robot.o
    $(LINK) $(LDFLAGS) -o $@ $^

clean:
    $(RM) -rf *.o skygrid

skygrid.o:  skygrid.cpp definitions.h commServer.h pose.h robot.h
commServer.o:   commServer.cpp commServer.h
pose.o:     pose.cpp pose.h
robot.o:    robot.cpp robot.h pose.h

My Errors:

/home/fari/Desktop/FarahSkygrid/skygrid/src/skygrid.cpp:1094: undefined reference to `stdscr'
/home/fari/Desktop/FarahSkygrid/skygrid/src/skygrid.cpp:1094: undefined reference to `stdscr'
/home/fari/Desktop/FarahSkygrid/skygrid/src/skygrid.cpp:1094: undefined reference to `stdscr'
/home/fari/Desktop/FarahSkygrid/skygrid/src/skygrid.cpp:1094: undefined reference to `stdscr'
/home/fari/Desktop/FarahSkygrid/skygrid/src/skygrid.cpp:1104: undefined reference to `werase'
/home/fari/Desktop/FarahSkygrid/skygrid/src/skygrid.cpp:1106: undefined reference to `wprintw'
/home/fari/Desktop/FarahSkygrid/skygrid/src/skygrid.cpp:1107: undefined reference to `wprintw'
/home/fari/Desktop/FarahSkygrid/skygrid/src/skygrid.cpp:1109: undefined reference to `wprintw'
/home/fari/Desktop/FarahSkygrid/skygrid/src/skygrid.cpp:1111: undefined reference to `stdscr'
/home/fari/Desktop/FarahSkygrid/skygrid/src/skygrid.cpp:1111: undefined reference to `wgetch'
/home/fari/Desktop/FarahSkygrid/skygrid/src/skygrid.cpp:1116: undefined reference to `wtouchln'

Answer

Ogre picture Ogre · Jun 30, 2012

I was having this problem with an ncurses program on Centos 6.2. It turns out that ncurses is sometimes split into two libraries, ncurses and tinfo. In my case, stdscr exists in libtinfo, not in libncurses, so adding -ltinfo to the link line, after -lncurses, solved the problem.