undefined reference to `sqrt'#include #include double safe_sqr(double _d_num){printf("%lf\n",_d_num);double d_temp_value = abs((int)_d_num);printf("%lf\n",d_temp_value);return sqrt(d_temp_value);}int main(int argc,char *argv[]){double d_value = safe_sqr(100.0);printf("%lf\n",d_value);return 0;}

问题描述:

undefined reference to `sqrt'
#include
#include
double safe_sqr(double _d_num)
{
printf("%lf\n",_d_num);
double d_temp_value = abs((int)_d_num);
printf("%lf\n",d_temp_value);
return sqrt(d_temp_value);
}
int main(int argc,char *argv[])
{
double d_value = safe_sqr(100.0);
printf("%lf\n",d_value);
return 0;
}

我的答案实在Linux环境下:
实际上是没有链接math数学库,所以要 :$gcc test.c –lm //-lm就是链接到math库.
这样会生成 a.out 文件.直接执行就可以了:$./a.out