|  | 
 
| 
代码如下:
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  
 #include<stdio.h>
 #include<math.h>
 
 int main()
 {
 unsigned long long sum=0;
 unsigned long long temp;
 unsigned long long weight;
 
 int i;
 
 for (i=0; i<64; i++)
 {
 temp = pow(2,i);
 sum = sum + temp;
 }
 
 weight = sum/25000;
 
 printf("有%llu粒麦子\n",sum);
 printf("共%llu公斤\n",weight);
 
 return 0;
 }
 
 无法正常运行,报错信息如下:
 
 In function 'main':         work52.c:(.text+0x35): undefined reference to 'pow'
 collect1:         ld returned 1 exit status
 
 谢谢帮助,祝您学业有成,工作顺利。
 
转:当你用linux环境使用pow()函数时,头文件也包含#include<math.h>在编译时出现了错误;
 gcc test11.c && ./a.out提示了一下错误
 
 用gcc编译出现的错误:
 undefined reference to `pow’
 
 解决方法:
 添加头文件#include<math.h>只需在编译时加入-lm
 如:gcc test11.c -lm && ./a.out
 
 | 
 |