what is 'undefined reference to `pow'' [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-19 05:52:07

问题


I have a codepad .

On line 15 inside a for function

 for(i=2; i<=90; i+=2){
    int j=0+i;
    printf("%i\n",i);
    power=pow(inp,j);
    factor=factorial(i);
    if(i%4==0)fAns += power/factor;
    else fAns -= power/factor;
  }

the line power=pow(inp,j); I added j instead of just using i because it gave me the same error. undefined reference to 'pow'.

If I replace j with 2, then it works just fine but when I use j=i it wont work. Is there a problem with incrementing this line?

I want this to increment and not throw me an error.


回答1:


You need to link with the math library. With gcc, this would mean passing -lm during linking.

The reason it doesn't complain when you use 2 as the exponent value is because the compiler is optimizing the pow call out.



来源:https://stackoverflow.com/questions/10167714/what-is-undefined-reference-to-pow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!