重複の可能性:
Cにファイルを含める
RunCを使用して、powとfloor/truncateを必要とする単純な関数を記述しています。math.hを含めました。メインの機能を使ってみると問題ありません。しかし、別のint関数を作成しようとすると、突然RunCにpow関数とfloor関数がなくなり、エラーが発生します。何か助けはありますか?
コードは次のとおりです。main()は機能しますが、まったく同じことを行う上記の関数を使用するように切り替えると、機能しません。
#include <stdio.h>
#include <math.h>
int sumofsquares(int x){
int counter = 0;
int temp = x;
while (temp != 0 || counter == 100){
//temp = temp - (int)pow(floor(sqrt(temp)), 2);
//temp = temp - pow(temp, 0.5);
printf("%d\n", temp);
counter = counter + 1;
}
/*while(temp != 0){
temp = temp - (int)pow(floor(sqrt(temp)), 2);
counter ++;
}*/
return counter;
}
int main(void){
printf("%d", (int)pow(floor(sqrt(3)), 2));
}
これを行う:
#include <stdio.h>
#include <math.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;
}
int main(void){
printf("%d", sumofsquares(3));
}
このエラーを返します:
/tmp/cctCHbmE.o: In function `sumofsquares':
/home/cs136/cs136Assignments/a04/test.c:9: undefined reference to `sqrt'
/home/cs136/cs136Assignments/a04/test.c:9: undefined reference to `floor'
collect2: ld returned 1 exit status