关于连接math.h的问题

软件和网站开发以及相关技术探讨
回复
头像
dugowe
帖子: 34
注册时间: 2006-06-14 13:43
联系:

关于连接math.h的问题

#1

帖子 dugowe » 2006-10-19 18:36

#include <stdio.h>
dugowe@dugowesbox:~/program$ more power.c
#include <math.h>

int main()
{
float x = 10;
float y = 2;
float z;

z = power(x, y);
printf("%d",z);
return 0;
}
dugowe@dugowesbox:~/program$ gcc power.c -lm -o power
/tmp/ccqeMycv.o: In function `main':power.c:(.text+0x3c):对‘power’未定义的引用
collect2: ld 返回 1
----------------------------
lib中也没见math函数库,只有
libm-2.3.6.so
libmemusage.so
libm.so.6
我想知道这个到底是该怎么写?从新利得上面也没找到math库,呵呵,
谢谢大家帮忙
头像
jaguar00
帖子: 227
注册时间: 2005-10-19 23:48
来自: 大山丛林

#2

帖子 jaguar00 » 2006-10-19 23:38

lay in :

/usr/include .


if not ,go to

/usr/local/include to find
图片It is no use doing what you like; you have got to like what you do!
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

Re: 关于连接math.h的问题

#3

帖子 leal » 2006-10-20 1:17

dugowe 写了:#include <stdio.h>
dugowe@dugowesbox:~/program$ more power.c
#include <math.h>

int main()
{
float x = 10;
float y = 2;
float z;

z = power(x, y);
printf("%d",z);
return 0;
}
dugowe@dugowesbox:~/program$ gcc power.c -lm -o power
/tmp/ccqeMycv.o: In function `main':power.c:(.text+0x3c):对‘power’未定义的引用
collect2: ld 返回 1
----------------------------
lib中也没见math函数库,只有
libm-2.3.6.so
libmemusage.so
libm.so.6
我想知道这个到底是该怎么写?从新利得上面也没找到math库,呵呵,
谢谢大家帮忙
你确定有 power函数吗?去查查标准库函数吧

power -> pow !

libm 就是 数学库
用心×恒 | 豆瓣 | 门户 | Blog
头像
dugowe
帖子: 34
注册时间: 2006-06-14 13:43
联系:

#4

帖子 dugowe » 2006-10-20 9:00

dugowe@dugowesbox:~/program$ gcc power.c -L /usr/lib -lm.a -o power
/usr/bin/ld:找不到 -lm.a
collect2: ld 返回 1

---------------
那个函数应该有吧,标准c的函数阿,

/usr/bin/ld:找不到 -lm.a
这个地方我不太明白。。能给稍微说一下吗?
头像
nobrain
帖子: 808
注册时间: 2005-08-25 13:58
来自: ustc
联系:

#5

帖子 nobrain » 2006-10-20 9:41

代码: 全选

gcc power.c -lm -o power
爱喝真猪奶茶的夜鸣猪
头像
dugowe
帖子: 34
注册时间: 2006-06-14 13:43
联系:

#6

帖子 dugowe » 2006-10-20 16:12

nobrain 写了:

代码: 全选

gcc power.c -lm -o power
不行的,试了好多遍了
头像
jaguar00
帖子: 227
注册时间: 2005-10-19 23:48
来自: 大山丛林

#7

帖子 jaguar00 » 2006-10-21 1:28

你是不是不pow弄成power?我怎么用c从来没有用到过这个‘标准函数’?

我帮你在gnu c library(postfix reference)中查过了,没有这个函数,还特意在 Mathematics: Math functions, useful constants, random numbers. 中从头看到尾怎么都没有?
图片It is no use doing what you like; you have got to like what you do!
头像
jaguar00
帖子: 227
注册时间: 2005-10-19 23:48
来自: 大山丛林

#8

帖子 jaguar00 » 2006-10-21 2:19

想起来了,在stl的algorithms中是有一个power的函数。不过是c++啊。不是c

不过是用在 #include <numeric>中的

原型是:


#include <numeric>
inline TYPE power( TYPE x, int N );

The power() function returns x raised to the power of N, where N is some non-negative integer.

-------------
c中只有pow
图片It is no use doing what you like; you have got to like what you do!
头像
ngc1275
帖子: 21
注册时间: 2006-08-22 18:05

#9

帖子 ngc1275 » 2006-11-12 21:37

函数 pow(计算次方值)
-------------
相关函数
exp,log,log10
表头文件
#include<math.h>
定义函数
double pow(double x,double y);
函数说明
pow()用来计算以x为底的y次方值,即xy值,然后将结果返回。
返回值
返回x的y次方计算结果。
错误代码
EDOM 参数x为负数且参数y不是整数。
附加说明
使用GCC编译时请加入-lm。
范例
#include <math.h>
main()
{
double answer;
answer =pow(2,10);
printf("2^10 = %f\n", answer);
}
执行
2^10 = 1024.000000
头像
dugowe
帖子: 34
注册时间: 2006-06-14 13:43
联系:

#10

帖子 dugowe » 2006-11-19 13:14

o ..xie le
hehe


gao hao le!!
回复