一个关于简单函数调用的问题,百思不得其解
#include <stdio.h>
#include <math.h>
int main(void)
{
float pi ;
float pisqrt;
pi = 3.14;
pisqrt = sqrtf(3.14 );//<-----------这里不同
printf("pi=%f\n",pi);
printf("pisqrt = %f\n",pisqrt);
return 0;
}
--------------------------------------
结果正常:
[root@zhangyong develop]# make
gcc -c study.c -o study.o
gcc study.o -o study
[root@zhangyong develop]# ./study
pi=3.140000
pisqrt = 1.772004
[root@zhangyong develop]#
-------------------------------------
而改成变量,就不对了
#include <stdio.h>
#include <math.h>
int main(void)
{
float pi ;
float pisqrt;
pi = 3.14;
pisqrt = sqrtf(pi);//<-----------这里不同
printf("pi=%f\n",pi);
printf("pisqrt = %f\n",pisqrt);
return 0;
}
------------------------------------
结果:
[root@zhangyong develop]# make
gcc -c study.c -o study.o
gcc study.o -o study
study.o(.text+0x2b): In function `main':
: undefined reference to `sqrtf'
collect2: ld returned 1 exit status
make: *** [study] 错误 1
[root@zhangyong develop]#