请教下高手。我使用红帽9.0版本自带的gcc3.2.2版本编译如下文件
#include "stdio.h"
main()
{
char g;
while(1)
if(kbhit())
{
g=getchar();
if(g=='c')
exit(0);
}
}
出现如下错误:
undefine reference to 'kbhit'
undefine reference to 'getchar'
请问这个问题出在什么地方
gq_gq831001 于 2008-11-12 14:23:52发表:
谢谢我现在安装了gcc3.4.0但报错/usr/bin/ld:cannot open c++/lin
collect2:ld returned 1 exit status
没本 于 2008-11-11 18:26:51发表:
第一行改为#include
第二行改为int main(),函数体}前面插一行return 0;
getchar()函数返回值是int
kbhit()函数不存在于Linux的C标准库中,是MS DOS下Borland Turbo C的C库函数。
程序在gcc 4.3.2/glibc 2.8 环境下编译通过。不推荐老掉牙的RH 9的gcc3.x[code]#include
#include
#include
int kbhit(void)
{
struct timeval tv;
fd_set read_fd;
/* Do not wait at all, not even a microsecond */
tv.tv_sec=0;
tv.tv_usec=0;
/* Must be done first to initialize read_fd */
FD_ZERO(&read_fd);
/* Makes select() ask if input is ready:
* 0 is the file descriptor for stdin */
FD_SET(0,&read_fd);
/* The first parameter is the number of the
* largest file descriptor to check + 1. */
if(select(1, &read_fd,NULL, /*No writes*/NULL, /*No exceptions*/&tv) == -1)
return 0; /* An error occured */
/* read_fd now holds a bit map of files that are
* readable. We test the entry for the standard
* input (file 0). */
if(FD_ISSET(0,&read_fd))
/* Character pending on stdin */
return 1;
/* no characters were pending */
return 0;
}
int main()
{
while(1)
{
if( kbhit() )
{
int g = getchar();
if( g=='c' )
exit(0);
}
}
return 0;
}[/code]
[ 本帖最后由 没本 于 2008-11-11 18:27 编辑 ]