Stages

  • preprocessing - Text substitution, stripping comments, and file inclusion.
g++ -E main.cpp -o main.i
  • compilation - Compilation of the processed source code into assembly language.
g++ -S main.i -o main.s
# or
g++ -S main.cpp -o main.s
  • assembler - Conversion of assembly code into machine code.
as main.s -o main.o
# or
g++ -c main.cpp -o main.o
  • linker - Produce a single executable program file. It combines our program with startup code, such as the following:
    • Standard code at the beginning of the program to set up the running environment to pass command-line parameters and environmental variables.
    • Standard code at the end of the program to pass back a return code.
g++ main.cpp -o main

Flags

  • -E Run the preprocessing stage.
  • -S Run the preprocessing and compilation stages.
  • -c Run the preprocessing, compilation, and assemble stages.
  • -o file Write output to file.
  • -llibrary, -l library Search the library named library when linking.
  • -Idir Add dir to the list of directories to be searched for header files.
  • -Ldir Add dir to the list of directories to be searched for -l.
  • -Wall Enable all warnings about some constructions considered questionable by some users.
  • -O Enable optimization.