编译时出现cos()错误 [英] cos() error when compiling
本文介绍了编译时出现cos()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次我尝试编译此代码时都会收到此错误:
未定义引用`cos''
collect2:ld返回1退出状态
我不明白什么是错的。有人可以解释为什么继续得到这个错误,即使我有< math.h>>?
Every time I try to compile this code I get this error:
undefined reference to `cos''
collect2: ld returned 1 exit status
I don''t understand what''s wrong. Can someone please explain why keep getting this error even though I have <math.h>>?
#include <stdio.h>
#include <math.h>
int main (){
double range, value;
int count,offset, sp;
printf("For loop example - simple cosine graph\n\n");
range = 0.0;
for(count = 1; range <= 40; count++){
value = cos (range); //caldulate value
//convert decimal value into interger to use
//as number of blanks to display
offset = (value + 1.0) * 15.0;
//display the indicated number of blanks
for (sp=0; sp < offset; sp++)
printf(" ");
//display the mrker for the graph
printf("*\n");
range += 0.5;
}
return 0;
}
推荐答案
你应该与数学库联系,例如
You should link with the math library, e.g.
gcc myapp.c -o myapp -lm
The documentation[^] states: "Link with -lm".
这篇关于编译时出现cos()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文