g++ are both compiler drivers. First one is used for C applications while the last one for C++.
Even so, they both can be used interchangeably (e.g. use gcc for C++ or g++ for C). This is because in the end both will end up using the same tools (at least for
.cpp files) for running the desired action, only the default flags used will differ. This can be analysed by appending the flag
-v to both drivers, which will make them output the things done in the background.
The table below shows the notable differences.
|Driver command||Compiler flags||Assembler flags||Linker flags|
g++ is equivalent to
gcc -shared-libgcc -lstdc++ -lm and for c files, g++ will also use the compiler
cc1plus while gcc will use
Later edit: If you're interested in the --as-needed flag you can checkout this stackoverflow link