LinuxSir.cn,穿越时空的Linuxsir!

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

sqrt() gnu C编译出错

[复制链接]
发表于 2006-8-31 22:36:55 | 显示全部楼层 |阅读模式
源代码assert.c:

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <assert.h>

  5. double my_sqrt(double x)
  6. {
  7.         assert(x >= 0.0);
  8.         return sqrt(x);
  9. }

  10. int main()
  11. {
  12.         printf("sqrt +2 = %g\n", my_sqrt(2.0));
  13.         printf("sqrt -2 = %g\n", my_sqrt(-2.0));
  14.         exit(0);
  15. }
复制代码

------------------------------------------------------------------
编译过程:

  1. [zxz@localhost chapter10]$ gcc -Wall -o assert assert.c
  2. /tmp/ccGnOiR2.o(.text+0x45): In function `my_sqrt':
  3. assert.c: undefined reference to `sqrt'
  4. collect2: ld 返回 1
  5. [zxz@localhost chapter10]$
复制代码

书上的例子啊,何解?
发表于 2006-8-31 22:39:32 | 显示全部楼层
gcc -Wall -lm -o assert assert.c
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-8-31 22:42:16 | 显示全部楼层
Post by Lolita
gcc -Wall -lm -o assert assert.c

谢谢,学习学习.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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