c – 使用ncurses时对`stdscr’的未定义引用

我试图在Ubuntu 11.10中编译我的代码并得到这些错误和更多.所以通过谷歌搜索它我认为这是一个链接错误.具体来说,有建议确保您拥有正确的标头并链接-lncurses库.我已经这样做了.我仍然收到这个错误.我还读到可能是我应该安装libncurses,但我已经安装了它.

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

我的错误:

/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'

解决方法:

我在Centos 6.2上使用ncurses程序遇到了这个问题.事实证明,ncurses有时会分成两个库,ncurses和tinfo.在我的例子中,stdscr存在于libtinfo中,而不存在于libncurses中,因此在-lncurses之后将-ltinfo添加到链接行解决了问题.

上一篇:在服务器上执行Java代码


下一篇:如何使用__pycache__文件夹运行Python项目?