What is the difference between g++ and gcc? Which one of them should be used for general c++ development?
What is the difference between g++ and gcc?
gcc has evolved from a single language "GNU C Compiler" to be a multi-language "GNU Compiler Collection". The term "GNU C Compiler" is still used sometimes in the context of C programming.
The g++ is the C++ compiler for the GNU Compiler Collection. Like gnat is the Ada compiler for gcc. see Using the GNU Compiler Collection (GCC)
For example, the Ubuntu 16.04 and 18.04 man g++ command returns the GCC(1) manual page.
The Ubuntu 16.04 and 18.04 man gcc states that ...
g++accepts mostly the same options asgcc
and that the default ...
... use of
gccdoes not add the C++ library.g++is a program that calls GCC and automatically specifies linking against the C++ library. It treats .c, .h and .i files as C++ source files instead of C source files unless -x is used. This program is also useful when precompiling a C header file with a .h extension for use in C++ compilations.
Search the gcc man pages for more details on the option variances between gcc and g++.
Which one should be used for general c++ development?
Technically, either gcc or g++ can be used for general C++ development with applicable option settings. However, the g++ default behavior is naturally aligned to a C++ development.
The Ubuntu 18.04 'gcc' man page added, and Ubuntu 20.04 continues to have, the following paragraph:
The usual way to run GCC is to run the executable called
gcc, ormachine-gccwhen cross-compiling, ormachine-gcc-versionto run a specific version of GCC. When you compile C++ programs, you should invoke GCC asg++instead.