以下程序無法在gcc中編譯。但它用g ++和MSC++以.c
擴展名編譯OK。一個gcc sqrt函數的bug?
#include <math.h>
#include <stdio.h>
int main()
{
double t = 10;
double t2 = 200;
printf("%lf\n", sqrt(t*t2));
return 0;
}
我的系統是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.
錯誤信息:
> gcc test.c
/tmp/ccyY3Hiw.o: In function `main':
test.c:(.text+0x55): undefined reference to `sqrt'
collect2: ld returned 1 exit status
這是一個錯誤?
任何人都可以爲我做一個測試?
另請參見http://stackoverflow.com/questions/1033898 – ephemient 2009-12-31 23:41:34