2023拉

Linux下undefined reference to `sqrt'

上一篇 / 下一篇  2013-02-17 16:51:57 / 个人分类:软件开发相关

源码:
#include<stdio.h>
#include <math.h>
int main(int argc,char **argv)
{
    float a=10,b=10;
    printf("%f\n",sqrt(a*b));
    return 0;
}
执行 gcc test.c -o test
提示
test.c:(.text+0x50): undefined reference to `sqrt'
collect2: ld returned 1 exit status

实在Linux环境下:
实际上是没有链接math数学库,所以要 :gcc test.c -lm -o test //-lm就是链接到math库。


TAG:

 

评分:0

我来说两句

Open Toolbar