以下程序无法在gcc中编译.但它与g ++和MSC++的.c扩展编译正常.
#include <math.h>
#include <stdio.h>
int main()
{
double t = 10;
double t2 = 200;
printf("%lf\n", sqrt(t*t2));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的系统是CentOS,版本信息.
> gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Run Code Online (Sandbox Code Playgroud)
错误信息:
> gcc test.c
/tmp/ccyY3Hiw.o: In function `main':
test.c:(.text+0x55): undefined reference to `sqrt'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
这是一个错误吗?
任何人都可以为我做测试吗?
Tom*_*Tom 19
你有没有连接数学库?
gcc -lm test.c -o test
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2296 次 |
| 最近记录: |