分页: 1 / 1

关于连接math.h的问题

发表于 : 2006-10-19 18:36
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库,呵呵,
谢谢大家帮忙

发表于 : 2006-10-19 23:38
jaguar00
lay in :

/usr/include .


if not ,go to

/usr/local/include to find

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

发表于 : 2006-10-20 1:17
leal
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 就是 数学库

发表于 : 2006-10-20 9:00
dugowe
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
这个地方我不太明白。。能给稍微说一下吗?

发表于 : 2006-10-20 9:41
nobrain

代码: 全选

gcc power.c -lm -o power

发表于 : 2006-10-20 16:12
dugowe
nobrain 写了:

代码: 全选

gcc power.c -lm -o power
不行的,试了好多遍了

发表于 : 2006-10-21 1:28
jaguar00
你是不是不pow弄成power?我怎么用c从来没有用到过这个‘标准函数’?

我帮你在gnu c library(postfix reference)中查过了,没有这个函数,还特意在 Mathematics: Math functions, useful constants, random numbers. 中从头看到尾怎么都没有?

发表于 : 2006-10-21 2:19
jaguar00
想起来了,在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

发表于 : 2006-11-12 21:37
ngc1275
函数 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

发表于 : 2006-11-19 13:14
dugowe
o ..xie le
hehe


gao hao le!!