问题
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'
回答1:
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.
回答2:
I know you've moved on, but for future reference: my guess is that the problem is in the placement of the -l argument. Try:
skygrid: skygrid.o commServer.o pose.o robot.o
$(LINK) -o $@ $^ $(LDFLAGS)
For more information, see the gcc manual: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
and this thread on SO: Placement of `-l' option in gcc
回答3:
Since the error messages refer to specific lines in your skygrid.cpp
source file, they're not linker errors.
You probably need to add
#include <curses.h>
to the top of that source file.
回答4:
user1246043,
I've been having a similar problem. Basically, I can't compile wiht g++ 4.5 or g++ 4.6, so I installed g++ 4.4 and used that. This specifically solved my problem with linking to ncursesw.
# Makefile:
CXX=g++-4.4
CXXLIBS=-lncursesw
CXXFLAGS=-Wall
# Other stuff omitted
回答5:
I came up with the same problem when building cscope 15.8.
After ./configure
, I first get error saying "ncurses.h" not found. It's because there is no libncurses-dev installed on my os.
After installing libcurses-dev, I run make
directly. Then got dozens of the "undefined reference to" error.
After rebuild from start again, these errors were gone.
./configure
make
回答6:
I faced with similar problem, when use Qt timer and ncurses: timeout macros ruin out Qt code =)
Solution was "#undef timeout"
after #include <ncurses.h>
to prevent macros from working. And if in some cases You will need ncurses timeout, you can run wtimeout(stdscr,delay)
directly.
来源:https://stackoverflow.com/questions/9541679/undefined-reference-to-stdscr-while-using-ncurses