什么是“未定义的引用'战俘'' [英] what is 'undefined reference to `pow''

查看:124
本文介绍了什么是“未定义的引用'战俘''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 codePAD

在里面的功能线15

 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;
  }

功率= POW(INP,J); 我加入Ĵ,而不是仅仅使用 I ,因为它给了我同样的错误。 未定义引用'战俘'

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'.

如果我更换Ĵ 2个,那么它工作得很好,但是当我使用 J = 习惯它工作。有一个问题,增加此行?

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.

推荐答案

您需要用数学库链接。与海湾合作委员会,这意味着通过 -lm 链接过程中。

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

当你使用它不抱怨的原因 2 的指数值是因为编译器优化 POW 叫唤。

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

这篇关于什么是“未定义的引用'战俘''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆