我想做一个涉及sqrt()
,floor()
和的简单函数pow()
。所以,我包括<math.h>
. 当我尝试使用我的功能时,我的程序会这样说sqrt()
并且floor()
不存在。我已经三次检查了我的文件并重写了它们,但它仍然给出了同样的错误。只是为了检查目录是否有任何问题<math.h>
,我制作了另一个单独的文件来计算相同的东西并且它有效。我现在一头雾水。我究竟做错了什么?
非功能程序的代码:
#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;
}
工作测试文件:
#include <stdio.h>
#include <math.h>
int main(void){
printf("%d", (int)pow(floor(sqrt(3)), 2));
}
错误是这样的
/tmp/ccm0CMTL.o:在函数 sumofsquares' 中:/home/cs136/cs136Assignments/a04/sumofsquares.c:9:未定义对 sqrt 的引用'/home/cs136/cs136Assignments/a04/sumofsquares.c:9:未定义引用楼层'collect2:ld返回1退出状态`
我在虚拟 Ubuntu 操作系统上使用 runC 进行编译