g++比gcc对c的支持更好???
发表于 : 2008-11-29 8:49
真奇怪,我编得复杂的c程序,用gcc编译一大堆警告,g++却没事,而且貌似c99标准也支持的很好,怎么回事呀~~~
代码: 全选
#include<stdio.h>
#include<math.h>
#include<string.h>
double fc(char *s,double a,double b)
{
double rtn;
if (strcmp(s,"abs")==0) rtn=fabs(a);
if (strcmp(s,"ln")==0) rtn=log(a);
if (strcmp(s,"exp")==0) rtn=exp(a);
if (strcmp(s,"sqr")==0) rtn=a*a;
if (strcmp(s,"sqrt")==0) rtn=sqrt(a);
if (strcmp(s,"int")==0) rtn=trunc(a);
if (strcmp(s,"rnd")==0) rtn=round(a);
if (strcmp(s,"hypot")==0) rtn=hypot(a,b);
return rtn;
}
int main(void)
{
return 0;
}
代码: 全选
/home/cuihao/Desktop/tt.c: 在函数‘fc’中:
/home/cuihao/Desktop/tt.c:15: 警告: 隐式声明与内建函数‘trunc’不兼容
/home/cuihao/Desktop/tt.c:16: 警告: 隐式声明与内建函数‘round’不兼容
/tmp/cch40gfh.o: In function `fc':
tt.c:(.text+0x5b): undefined reference to `log'
tt.c:(.text+0x80): undefined reference to `exp'
tt.c:(.text+0xd9): undefined reference to `sqrt'
tt.c:(.text+0x104): undefined reference to `trunc'
tt.c:(.text+0x129): undefined reference to `round'
tt.c:(.text+0x155): undefined reference to `hypot'
collect2: ld 返回 1
不是反过来么xhy 写了:g++只是个马甲,它用一堆参数调用了gcc
g++不是编译器,只是个外壳
ChloeRei 写了:不是反过来么xhy 写了:g++只是个马甲,它用一堆参数调用了gcc
g++不是编译器,只是个外壳
代码: 全选
man gcc
代码: 全选
However, the use of gcc does not add the C++ library. g++ is a program that calls GCC and treats .c, .h and .i files as
C++ source files instead of C source files unless -x is used, and automatically specifies linking against the C++
library. This program is also useful when precompiling a C header file with a .h extension for use in C++ compilations.
On many systems, g++ is also installed with the name c++.