What is the difference between g++ and gcc?
What is the difference between g++ and gcc? Which ones should be used for general c++ development?
gcc
and g++
are compiler-drivers of the 'Gnu Compiler Collection' (which was once upon a time just the 'Gnu C Compiler').
Even though they automatically determine which backends ( cc1
cc1plus
...) to call depending on the file-type, unless overridden with -x language
, they have some differences.
The probably most important difference in their defaults is which libraries they link against automatically.
According to GCC's online documentation link options and how g++ is invoked, g++
is equivalent to gcc -xc++ -lstdc++ -shared-libgcc
(the 1st is a compiler option, the 2nd two are linker options). This can be checked by running both with the -v
option (it displays the backend toolchain commands being run).
GCC: GNU Compiler Collection
gcc: GNU C Compiler
g++: GNU C++ Compiler
The main differences:
Extra Macros when compiling *.cpp files:
#define __GXX_WEAK__ 1
#define __cplusplus 1
#define __DEPRECATED 1
#define __GNUG__ 4
#define __EXCEPTIONS 1
#define __private_extern__ extern
For c++ you should use g++.
It's the same compiler (eg the GNU compiler collection). GCC or G++ just choose a different front-end with different default options.
In a nutshell: if you use g++ the frontend will tell the linker that you may want to link with the C++ standard libraries. The gcc frontend won't do that (also it could link with them if you pass the right command line options).
链接地址: http://www.djcxy.com/p/2458.html下一篇: g ++和gcc有什么区别?