Linux下链接问题(在线等待)

darkstar21cn 2004-06-22 10:29:12
我在程序中使用了getch (),已经把 #include <curses.h>加进来了,编译没问题,链接的时候就出问题了,提示如下:

test.o(.text+0x15): In function `main':
: undefined reference to `stdscr'
test.o(.text+0x1a): In function `main':
: undefined reference to `wgetch'
collect2: ld returned 1 exit status

是不是缺少库了?应该加哪个库进来?
...全文
162 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
CsdnRob 2004-07-02
  • 打赏
  • 举报
回复
1.in 快些 2.要看具体问题 不是所有时候IS NOT NULL效率都低
darkstar21cn 2004-06-22
  • 打赏
  • 举报
回复
csdn没人知道吗?
darkstar21cn 2004-06-22
  • 打赏
  • 举报
回复
难道Linux下没有可以不用回车就从键盘读取按键吗?
sharkhuang 2004-06-22
  • 打赏
  • 举报
回复
差库文件
darkstar21cn 2004-06-22
  • 打赏
  • 举报
回复
curses.h好像是xwindows的头文件之一吧?
darkstar21cn 2004-06-22
  • 打赏
  • 举报
回复
难道,Linux下没有可以不用回去就从键盘读取按键吗?
darkstar21cn 2004-06-22
  • 打赏
  • 举报
回复
不好意思运行又出问题了
./test
Segmentation fault
pacman2000 2004-06-22
  • 打赏
  • 举报
回复
要加上curses库。
-lcurses
darkstar21cn 2004-06-22
  • 打赏
  • 举报
回复
没有人碰到过这个问题吗?
darkstar21cn 2004-06-22
  • 打赏
  • 举报
回复
有人在吗?
darkstar21cn 2004-06-22
  • 打赏
  • 举报
回复
程序很简单,只有这几行,只是试试Linux下getch ()是怎么运行的

#include <iostream>
#include <curses.h>

using namespace std;

int main(int argc, char* argv[])
{
char sc;
while (true) {
sc = getch ();
cout << "getch () " << sc << endl;
}
return 0;
}
junnyfeng 2004-06-22
  • 打赏
  • 举报
回复
wgetch?你用到宽字符了?
kaphoon 2004-06-22
  • 打赏
  • 举报
回复
http://bbs.ee.ntu.edu.tw/boards/Programming/11/2/2.html
kaphoon 2004-06-22
  • 打赏
  • 举报
回复
查了一下,getch是linux下的bug
你可以用个方法替代getch
http://c-for-dummies.com/lessons/linux/04/
要多刷新几次,才能访问


About the getch(), Ive tried with the curses way but found it a bit unstylish... I have found a way to do it as follows:
void set_keypress(void) {
struct termios new_settings;
tcgetattr(0,&stored_settings);
new_settings = stored_settings;
new_settings.c_lflag &= (~ICANON);
new_settings.c_cc[VTIME] = 0;
tcgetattr(0,&stored_settings);
nnew_settings.c_cc[VMIN] = 1;
tcsetattr(0,TCSANOW,&new_settings);
}

This takes away the buffering in the Linux terminals so that you don't have to press the Enter key afterwards. You have to include the header file TERMIO.H. And after you run this code you can use the getchar() function and it works just like getch() does in Windows/DOS programs.

To reset you do as follows:

void reset_keypress(void) {
tcsetattr(0,TCSANOW,&stored_settings);
}
kaphoon 2004-06-22
  • 打赏
  • 举报
回复
先man getch
看看有没有,如果没有
在去(c++)头文件
grep getch *.h
看看有没有
确信在哪个文件中有
然后编译
再有问题
就连接库
hcj2002 2004-06-22
  • 打赏
  • 举报
回复
试一试加上头文件stdio.h

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧