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
-ERun the preprocessing stage.-SRun the preprocessing and compilation stages.-cRun the preprocessing, compilation, and assemble stages.-o fileWrite output to file.-llibrary,-l librarySearch the library named library when linking.-IdirAdd dir to the list of directories to be searched for header files.-LdirAdd dir to the list of directories to be searched for-l.-WallEnable all warnings about some constructions considered questionable by some users.-OEnable optimization.