为什么 Linux 上的 Curses 会出现以下错误?
尝试让 getch() 捕获按键操作。
#include <curses.h>
...
...
WINDOW *w;
char f;
w = initscr();
timeout(3000);
f = getch();
endwin();
给我以下错误:-
undefined reference to `wgetch'
undefined reference to `stdscr'
Trying to get getch() working to capture key press.
#include <curses.h>
...
...
WINDOW *w;
char f;
w = initscr();
timeout(3000);
f = getch();
endwin();
is giving me following error:-
undefined reference to `wgetch'
undefined reference to `stdscr'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个链接错误。您是否正确链接到curses库?
在 C 中使用库涉及两个步骤。
#include
相关的头文件。这样您的代码就知道库函数的签名是什么。所以你这样做是正确的。-lncurses
添加到编译行就可以了。这是链接说明。That's a linking error. Are you linking to the curses library correctly?
There are two steps involved in using a library in C.
#include
the relevant header files from your source files. This is so your code knows what signatures of the library functions are. So you're doing this correctly.-lncurses
to the compile line should do it. Here's an explanation of linking.上面的答案是正确的,但格式是:
gcc -Wall program.c -o name_of_binary -lncurses
当我这样做时:
gcc -Wall -lncurses program.c...
它不起作用,所以显然应该将其钉在最后。
The above answers are correct but the format is:
gcc -Wall program.c -o name_of_binary -lncurses
When I did:
gcc -Wall -lncurses program.c...
It did not work so apparently it should be tacked on the end.