What is gcc/g++

First of all: gccand g++ are two different things.

GCC: GNU Compiler Collection (GUN compiler collection), which can compile C, C++, JAV, Fortran, Pascal, Object-C, Ada and other languages.

gcc is the GUN C Compiler in GCC (C compiler)

g++ is the GUN C++ Compiler in GCC (C++ compiler)

An interesting fact is that, fundamentally, GCC (GNU Compiler Collection) and G++ are not compilers themselves, nor are they collections of compilers. They are simply drivers that, based on the file types specified in the command-line arguments, invoke the corresponding GNU compilers. For example, when you use GCC to compile a C file, several steps are involved:

Step 1: Call a preprocessor, such as cpp.
Step 2: Call an actual compiler, like cc or cc1.
Step 3: Call an assembler, like as.
Step 4: Call a linker, like ld.

Main differences

The main differences between gcc and g++ are as follows:

For *.c and *.cpp files, gcc treats them as C and C++ files respectively (C and C++ have different language syntax).

For *.c and *.cpp files, g++ treats them uniformly as C++ files.

When using g++ to compile files, it automatically links the Standard Template Library (STL), while gcc does not automatically link STL.

When compiling C files with gcc, there are fewer predefined macros available.

When compiling C++ files with gcc or g++ (both using the C++ file compiler), some additional macros are added, including:

#define __GXX_WEAK__ 1
#define __cplusplus 1
#define __DEPRECATED 1
#define __GNUG__ 4
#define __EXCEPTIONS 1
#define __private_extern__ extern

When using gcc to compile C++ files and you want to use the STL, you need to add the -lstdc++ flag. However, this does not mean that gcc -lstdc++ and g++ are equivalent; they have other differences beyond this.

Key Parameters:

-g: Enables debugging information (for improved GDB output).
-Wall: Enables most warning messages.
-O or -O2: Enables optimizations.
-o: Specifies the name of the output file.
-c: Outputs an object file (.o).
-I: Specifies an include directory.
-L: Specifies a library directory.
-l: Links with a library (e.g., lib.a).
Usage Example:
g++ -o helloworld -I/homes/me/randomplace/include helloworld.C