【发布时间】:2012-01-26 20:40:42
【问题描述】:
可能重复:
Problem using pow() in C
Undefined reference topow' andfloor'
我使用的是 gcc 4.6.1。
代码 sn-p:
int main(void)
{
int x= 2;
int y = pow(3,x);
printf("%d\n",y);
return 0;
}
终端:
avinash@titanic:~/Desktop/DSF$ gcc power.c -o power
/tmp/ccTJ7vAH.o: In function `main':
power.c:(.text+0x25): undefined reference to `pow'
collect2: ld returned 1 exit status
如果我将 x 替换为 2,那么它将以预期的方式执行。 pow 函数不接受变量作为参数吗?
注意:我在源文件中包含了 stdio.h 和 math.h。
【问题讨论】:
-
如果你有 pow(3,2) 编译器可以直接计算,而不必调用函数。
-
如果您在源文件中包含 stdio.h 和 math.h,请在代码中向我们展示,而不是向我们展示不完整的代码,然后告诉我们缺少什么。
-
@KeithThompson- 对不起。但是“包含”一词似乎是粗体,而实际上并不适用于粗体。所以我删除了#include 行,但我已经提到我已经包含了两个库。