在Linux下,使用gcc编译log,log10函数时报错,代码如下:
#include <stdio.h>
#include <math.h>
int main(void)
{
double input;
double test_para_1 = 20.0855;
double test_para_2 = 1000;
input = exp(9.0);
printf("The result is:%lf\n",input);
input = log(test_para_1);
printf("The result is:%lf\n",input);
input = log10(test_para_2);
printf("The result is:%lf\n",input);
return 0;
}
编译报错如下:

这是由于没有链接数学库造成的报错,只要在编译时在gcc后面加上-lm就可以了。

常见的库链接方法为:
数学库 -lm ; posix线程 -lpthread
本文介绍了一段在Linux环境下使用gcc编译包含log和log10函数的C代码时遇到的报错问题及解决方法。通过在编译命令中加入-lm参数成功链接数学库,解决了编译错误。
7072

被折叠的 条评论
为什么被折叠?



