LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 761|回复: 5

程序语法检查通过,但编译错误?

[复制链接]
发表于 2003-10-25 11:33:49 | 显示全部楼层 |阅读模式
# cat sound.c
#include "ctype.h"
main()
{
char yn='y';
while (toupper(yn) != 'N')
{
sound (1000);
delay (10*1000);
nosound ();
scanf("%c\n",&yn);
}
}

linux# gcc -c sound.c
linux# gcc sound.c
/tmp/ccY1CnnA.o: In function `main':
/tmp/ccY1CnnA.o(.text+0x34): undefined reference to `sound'
/tmp/ccY1CnnA.o(.text+0x44): undefined reference to `delay'
/tmp/ccY1CnnA.o(.text+0x4c): undefined reference to `nosound'
collect2: ld returned 1 exit status

不会是:ask :sk不懂,请大家帮帮忙,谢谢。
发表于 2003-10-25 11:57:03 | 显示全部楼层
undefined reference to xxx
表示

某个函数的定义没有找到
无法连接
发表于 2003-10-25 11:59:59 | 显示全部楼层
你的sound、delay、nosound函数从哪来的?
另外,include标准库的时候最好用尖括号(大于、小于号」
#include <ctype.h>
 楼主| 发表于 2003-10-25 12:54:28 | 显示全部楼层
谢谢,原来我看漏了,我是照书抄的,原来前一页还有一行:
#include <dos.h>
对不起了。我老是犯这些低级错误的。
但没有这个库函数。那里有:ask :ask
发表于 2003-10-25 15:05:40 | 显示全部楼层
是扬声器吗?
参考一下:
http://www.fanqiang.com/a4/b8/20010809/1200011095.html

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <linux/kd.h>

  6. int
  7. main()
  8. {
  9.   int fd;
  10.   int freq = 1000;
  11.   int delay = 2000000; /* 2秒 */

  12.   if((fd = open("/dev/console", O_WRONLY)) < 0){
  13.     fprintf(stderr, "cannot open /dev/console\n");
  14.     exit(-1);
  15.   }
  16.   ioctl(fd, KIOCSOUND, 1190000 / freq);
  17.   usleep(delay);
  18.   ioctl(fd, KIOCSOUND, 0);

  19.   exit(0);
  20. }
复制代码
 楼主| 发表于 2003-10-25 16:04:37 | 显示全部楼层
谢谢大家
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表