GCC:undefined reference to ‘sqrt’
用c语言求一个小于100000的一个整数,要求这个数加上100后是一个完整平方数,在加上268又是一个完整平方数,请问该数有哪些?
#include <stdio.h> #include <math.h> main(){ long int i,x,y; for(i=1;i<100000;i++){ x = sqrt(i+100); y = sqrt(i+268); if(x*x == i+100 && y*y == i+268){ printf("\n%ld\n",i); } } }
将以上代码保存成test02.c
通过gcc test02.c -o test02 执行的时候提示
undefined reference to `sqrt'
代码中是我是引入math.h类库的,提示没有找到!该问题为实际上没有链接math库,编译时需要加上 -lm 参数(链接math库)
通过执行 gcc -lm test02.c -o test02即可
热门日志
分类
- Django(4)
- ssdb(1)
- Mac(7)
- C(1)
- memcache(1)
- Python(32)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- about(1)
- git(9)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(2)
- 架构(18)
- Vue(1)
- game(2)
- Html(6)
- Java(8)
- Mysql(37)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(72)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Php(102)
- Windows(8)
- Message(48)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(12)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)