ubuntu下math.h头文件的编译问题

来源:互联网 发布:json环境搭建 编辑:程序博客网 时间:2024/05/17 23:02

在ubuntu下写了个2次方函数,如下:

/*************************************************************************> File Name: power.c> Author:AnSwEr > Mail:yuanweijie1993@gmail.com > Created Time: 2015年04月16日 星期四 20时02分29秒 ************************************************************************//*显示计算2的16次方*/#include<stdio.h>#include<math.h>#define N 16int main(){    int n;    printf("n\t2^n\n");    for(n=0;n<=N;n++)    {        printf("%d\t%d\n",n,(int)pow(2,n));    }    return 0;}
在编译时,出现如下错误:

/tmp/ccdDb1GN.o: In function `main':
power.c:(.text+0x38): undefined reference to `pow'
collect2: error: ld returned 1 exit status

提示没有找到指向pow函数的库,即找不到math.h。


解决方法:

在编译时加上-lm即可,表示告诉编译器到libm.so库文件中找这个函数,通常在/lib中。



0 0
原创粉丝点击