分页: 1 / 1

g++比gcc对c的支持更好???

发表于 : 2008-11-29 8:49
cuihao
真奇怪,我编得复杂的c程序,用gcc编译一大堆警告,g++却没事,而且貌似c99标准也支持的很好,怎么回事呀~~~

Re: g++比gcc对c的支持更好???

发表于 : 2008-11-29 12:20
BigSnake.NET
贴源码。。。

Re: g++比gcc对c的支持更好???

发表于 : 2008-11-29 14:04
cuihao
程序太长了,随便贴一个子函数:

代码: 全选

#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;
}
g++编译可以,gcc出一些莫名其妙的东东:

代码: 全选

/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

Re: g++比gcc对c的支持更好???

发表于 : 2008-11-29 14:10
BigSnake.NET
gcc a.c -std=c99 -lm

Re: g++比gcc对c的支持更好???

发表于 : 2008-11-29 14:28
cuihao
喔~~~可以了~谢谢
那个-lm是什么意思

Re: g++比gcc对c的支持更好???

发表于 : 2008-11-29 14:48
HuntXu
math库

Re: g++比gcc对c的支持更好???

发表于 : 2008-11-29 15:12
xhy
g++只是个马甲,它用一堆参数调用了gcc

g++不是编译器,只是个外壳

Re: g++比gcc对c的支持更好???

发表于 : 2008-11-30 11:46
ChloeRei
xhy 写了:g++只是个马甲,它用一堆参数调用了gcc

g++不是编译器,只是个外壳
:ema6 不是反过来么

Re: g++比gcc对c的支持更好???

发表于 : 2008-11-30 12:19
xhy
ChloeRei 写了:
xhy 写了:g++只是个马甲,它用一堆参数调用了gcc

g++不是编译器,只是个外壳
:ema6 不是反过来么

代码: 全选

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++.

Re: g++比gcc对c的支持更好???

发表于 : 2008-11-30 19:57
ChloeRei
奥,原来我想错了