我想做一个简单的函数,涉及sqrt()
,floor()
和pow()
。所以,我包括了<math.h>
。当我尝试使用我的功能时,我的程序说sqrt()
和floor()
不存在。我三重检查了我的文件并重写了它们,但它仍然给出了相同的错误。只是为了检查<math.h>
目录是否有任何问题,我做了另一个单独的文件,计算出相同的结果,并且它的工作。我现在无能为力。我究竟做错了什么?包含文件C
非运作程序的代码:
#include <math.h>
#include "sumofsquares.h"
int sumofsquares(int x){
int counter = 0;
int temp = x;
while(temp != 0){
temp = temp - (int)pow(floor(sqrt(temp)), 2);
counter ++;
}
return counter;
}
工作测试文件:
的错误是这样
/tmp/ccm0CMTL.o:在功能sumofsquares': /home/cs136/cs136Assignments/a04/sumofsquares.c:9:undefined reference to sqrt' /home/cs136/cs136Assignments/a04/sumofsquares.c:9:未定义 参考地板” collect2:LD返回1退出status`
我在虚拟的Ubuntu操作系统中使用runC编译
什么是确切的错误?你如何编译你的程序? – cnicutar 2012-02-22 17:07:10
@cnicutar:错误是这个'/tmp/ccm0CMTL.o:在函数'sumofsquares'中: /home/cs136/cs136Assignments/a04/sumofsquares.c:9:undefined对'sqrt'的引用 /home/cs136/cs136Assignments/a04/sumofsquares.c:9:未定义的引用'floor' collect2:ld返回1退出状态' 我在一个虚拟的Ubuntu操作系统上使用runC来进行complile。 – user1222282 2012-02-22 17:13:37
这是* linkage *问题,而不是* include *问题。通过cnicutar检查答案。 – karlphillip 2012-02-22 17:17:57