Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What is the difference between g++ and gcc?

What is the contrast between g++ and gcc? Which one of them ought to be utilized for general c++ development?
by

2 Answers

espadacoder11
GCC: GNU Compiler Collection

- Referrers to all the different languages that are supported by the GNU compiler.
gcc: GNU C Compiler
g++: GNU C++ Compiler

The main differences:

1. gcc will compile: .c\*.cpp files as C and C++ respectively.
2. g++ will compile: *.c\*.cpp files but they will all be treated as C++ files.
3. Also if you use g++ to link the object files it automatically links in the std C++ libraries (gcc does not do this).
4. gcc compiling C files has fewer predefined macros.
5. gcc compiling *.cpp and g++ compiling *.c\*.cpp files has a few extra macros.
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
sandhya6gczb
The difference between g++ and gcc are:
g++ can compile any .c or .cpp files but they will be treated as C++ files only whereas gcc can compile any .c or .cpp files but they will be treated as C and C++ respectively.

Command to compile C++ program through g++ is g++ fileName.cpp -o binary* whereas command to compile C program through gcc is *gcc fileName.c -o binary

Login / Signup to Answer the Question.