LinuxSir.cn,穿越时空的Linuxsir!

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

glibc中如何没有sin等三角函数?

[复制链接]
发表于 2004-5-9 13:34:54 | 显示全部楼层 |阅读模式
我按照载win下包含math.h后编译不过,后来发现math.h中根本没有sin函数。我又用按内容查找,也没有找到有sin函数定义的头文件。

如何是好?
发表于 2004-5-9 15:38:37 | 显示全部楼层
怎么会没有呢,你自己写个用三角函数的程序,看看编译出什么提示?
 楼主| 发表于 2004-5-9 19:34:22 | 显示全部楼层
用过了,提示错误,sin函数未定义:
/root/tmp/cc4i6vxv.o(.text+0x25): In function `main':
: undefined reference to `sin'
collect2: ld returned 1 exit status

源程序为:

  1. #include <math.h>
  2. main()
  3. {
  4.         int        x, y;
  5.         x=1;
  6.         y=sin(x);
  7. }

复制代码


gcc test.c -o test -g
发表于 2004-5-9 19:50:12 | 显示全部楼层
加上-lm编译。
gcc test.c -o test -g -lm
 楼主| 发表于 2004-5-9 21:36:40 | 显示全部楼层
多谢,但是-lm是什么意思呢?sin函数是定义再内核里吗?
发表于 2004-5-9 21:40:38 | 显示全部楼层
-g的意思是?
 楼主| 发表于 2004-5-9 22:06:44 | 显示全部楼层
加入调试符号啊
发表于 2004-5-10 07:42:09 | 显示全部楼层
最初由 tx-cary 发表
多谢,但是-lm是什么意思呢?sin函数是定义再内核里吗?


gcc不会自动连接math库,所以要手动加入 -lm
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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