undefined reference to 'stdscr'

本文介绍了一个简单的C程序中使用getch()函数遇到的问题及其解决方案。该程序试图从标准输入读取字符但链接阶段出现错误,提示未定义的引用。文章给出了解决方法,即通过链接curses库来解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include

int main()

{

    getch();

}

 

% gcc test.c

undefined reference to 'stdscr'

undefined reference to 'wgetch'

 

解决方法:

% gcc test.c -l curses

/tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'initscr' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'cbreak' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'noecho' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'stdscr' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'keypad' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'curs_set' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'stdscr' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'wtimeout' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'endwin' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'clear' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'stdscr' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'stdscr' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'refresh' /tmp/ccURoooa.o:test.cpp:function Game::input(): error: undefined reference to 'wgetch' collect2: error: ld returned 1 exit status run.sh: line 2: ./main: No such file or directory
04-04
/tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'initscr' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'cbreak' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'noecho' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'stdscr' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'keypad' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'curs_set' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'stdscr' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'wtimeout' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'endwin' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'clear' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'stdscr' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'stdscr' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'refresh' /tmp/ccGUDfOK.o:test.cpp:function Game::input(): error: undefined reference to 'wgetch' collect2: error: ld returned 1 exit status run.sh: line 2: ./main: No such file or directory
04-04
fatal: [192.168.10.120]: FAILED! => {"changed": true, "cmd": "cd /root/cmatrix-1.2a && ./configure && make -j 4 && make install", "delta": "0:00:01.380669", "end": "2025-03-11 01:29:24.799036", "msg": "non-zero return code", "rc": 2, "start": "2025-03-11 01:29:23.418367", "stderr": "configure: warning: \n*** No termcap lib available, consider getting the official ncurses\n*** distribution from ftp://ftp.gnu.org/pub/gnu/ncurses if you get\n*** errors compiling nano.\nconfigure: warning: \n\n*** You do not appear to have an X window fonts directory in the standard\n*** locations (/usr/lib/X11/fonts/misc or /usr/X11R6/lib/X11/fonts/misc). The\n*** mtx.pcf font will not be installed. This means you will probably not\n*** be able to use the mtx fonts in your x terminals, and hence be unable\n*** to use the -x command line switch. Sorry about that...\n\n/usr/bin/ld: cmatrix.o: in function `finish':\n/root/cmatrix-1.2a/cmatrix.c:86: undefined reference to `curs_set'\n/usr/bin/ld: /root/cmatrix-1.2a/cmatrix.c:87: undefined reference to `stdscr'\n/usr/bin/ld: /root/cmatrix-1.2a/cmatrix.c:87: undefined reference to `wclear'\n/usr/bin/ld: /root/cmatrix-1.2a/cmatrix.c:88: undefined reference to `stdscr'\n/usr/bin/ld: /root/cmatrix-1.2a/cmatrix.c:88: undefined reference to `wrefresh'\n/usr/bin/ld: /root/cmatrix-1.2a/cmatrix.c:89: undefined reference to `resetty'\n/usr/bin/ld: /root/cmatrix-1.2a/cmatrix.c:90: undefined reference to `endwin'\n/usr/bin/ld: cmatrix.o: in function `c_die':\n/root/cmatrix-1.2a/cmatrix.c:106: undefined reference to `curs_set'\n/usr/bin/ld: /root/cmatrix-1.2a/cmatrix.c:107: undefined reference to `stdscr'\n/usr/bin/ld: /root/cmatrix-1.2a/cmatrix.c:107: undefined reference to `wclear'\n/usr/bin/ld: /root/cmatrix-1.2a/cmatrix.c:108: undefined reference to `stdscr'\n/usr/bin/ld: /root/cmatrix-1.2a/cmatrix.c:108: undefined reference to `wrefresh'\n/usr/bin/ld: /ro
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值