阅读math.h的文档,似乎我应该做的就是包含math.h,并使用包含的数学函数,如sqrt。问题是我试图在我的程序中使用sqrt时出现以下错误。我试过math.sqrt,但那也没用。任何想法我做错了什么?在C中使用math.h sqrt函数
undefined reference to `sqrt'
...
#include <stdio.h>
#include <math.h>
int main (int argc, char *argv[])
{
int a, b;
a = 1;
b = 5;
if (a < sqrt (b))
printf("1 < sqrt(5)");
return 0;
}
也许用'-lm'选项 – BLUEPIXY
我知道它说'sin',但它是任何数学函数相同。 – hammar