Open Source‎ > ‎

Compilation Phases

Most modern compilers do not create an executable from high level source code in single go, but the overall compilation is performed in different phases. A typical compilation of a program from High level language program to final executable comprises of the following phases:
  • Preprocessing
  • Compilation
  • Assembly
  • Linking
There are individual commands for each of the stages which are used by gcc. However, gcc makes the transition from one phase to another completely transparent to the programmer. However, to understand the different we can use these commands.
 Phase Command  Input  Output 
 Preprocessing  cpp High Level Program containing Macros   High level program with macros expanded
 Compilation gcc High level program with macros expanded Assembly Code
 Assembly  as  Assembly Code Object File 
 Linking  ld Object file  Executable

Although gcc hides all the intermediate phases from the programmer but gcc can be requested to save the intermediate files for debugging purposes by using the -save-temps option.gcc would save the intermediate files with the following extension

 Pre-processed file filename.i 
 Assembly file filename.s
 Object file filename.o