LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   What's the different between gcc and g++ ? (https://www.linuxquestions.org/questions/programming-9/whats-the-different-between-gcc-and-g-669821/)

Jacky Quah 09-14-2008 04:52 AM

What's the different between gcc and g++ ?
 
hi, what's the different between
gcc -std=c++98 and g++ ?

Files Test.cpp
Code:

#include <stdio.h>

int main(int argc, char *argv[]){
  printf("Test");
}

I compiled with
g++ Test.cpp
it's fined

but when I compiled with
gcc -std=c++98 Test.cpp or gcc Test.cpp
it's error and print
[quote]
/tmp/ccmerMxh.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
[/qoute]

why is that ?

matthewg42 09-14-2008 05:33 AM

From the gcc manual page:
Quote:

In C mode, this is equivalent to -std=c89. In C++ mode, it is equivalent to -std=c++98.

This turns off certain features of GCC that are incompatible with ISO C90 (when compiling C code), or of standard C++ (when compiling C++ code), such as the "asm" and "typeof" keywords, and predefined macros such as "unix" and "vax" that identify the type of system you are using. It also enables the undesirable and rarely used ISO trigraph feature. For the C compiler, it disables recognition of C++ style // comments as well as the "inline" keyword.

The alternate keywords "__asm__", "__extension__", "__inline__" and "__typeof__" continue to work despite -ansi. You would not want to use them in an ISO C program, of course, but it is useful to put them in header files that might be included in compilations done with -ansi. Alternate predefined macros such as "__unix__" and "__vax__" are also available, with or without -ansi.

The -ansi option does not cause non-ISO programs to be rejected gratuitously. For that, -pedantic is required in addition to -ansi.

The macro "__STRICT_ANSI__" is predefined when the -ansi option is used. Some header files may notice this macro and refrain from declaring certain functions or defining certain macros that the ISO standard doesn’t call for; this is to avoid interfering with any programs that might use these names for other things.

Functions that would normally be built in but do not have semantics defined by ISO C (such as "alloca" and "ffs") are not built-in functions when -ansi is used.

Jacky Quah 09-14-2008 06:05 AM

That's still doesn't answer my question.

I mean what's the different between :
g++ and gcc -std=c++98

when I compile with the code of my first post.
g++ compiled fine.
but
gcc -std=c++98
produce error as I stated before.

why is it like that ?
the code is standard C, if I am not wrong.

I want to try to compile if standard c library is work in c++ (g++ and gcc -std=c++98).

it worked in g++ but why it didn't work on gcc -std=c++98 ?

keefaz 09-14-2008 06:49 AM

Note that the error says ld returned 1 exit status, so it is not gcc that makes the error, but rather ld that does not find the reference to __gxx_personality_v0, at least that is how I understand it
A quick google search shows me that __gxx_personality_v0 is defined by the libstdc++.so library

Maybe this will work: gcc -std=c++98 -lstdc++ Test.cpp

dmail 09-14-2008 06:52 AM

Quote:

gcc -std=c++98
produce error as I stated before.
This option is invalid for C as it is a C++ option, the option you want is quoted in matthewg42's post (-std=c89).
__gxx_personality_v0 is related to C++ exceptions and I would surmise the compiler is getting confused due to the file extension. Instead try compiling the code with "gcc -x c Test.cpp" which overrides the file extension.


All times are GMT -5. The time now is 02:21 AM.