我正在尝试设置一个函数指针以指向该pow
函数。这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void){
double (*func)(double, double) = pow;
return 0;
}
但是该程序无法编译。我收到此错误:
$ gcc test.c -o test
/tmp/ccD6Pmmn.o: In function `main':
test.c:(.text+0x8): undefined reference to `pow'
collect2: error: ld returned 1 exit status
我正在使用Ubuntu 15.10。
有人知道我的代码有什么问题吗?
谢谢
您需要通过命令行使用-lm进行编译,或者配置您的IDE以将其添加到链接过程中。这是由于以下事实:有些库非常大,并且为了避免在程序和编译时间中占用空间,这是在C的开头设置的,当时计算机运行速度慢得多,将花费更多的编译时间和空间是CRUCIAL。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句