Blog Detail

blog
Compilation Stages in GCC

The Four Stages of Compiling a C Program

  1. Pre-Processor
  2. Translator
  3. Assembler
  4. Linker 

1) Pre-Processor:-

i) Include header file
ii)Replace macro
iii)Remove the comments
iv)Convert .c file to .i file
v) .i file is also called pure c file 
 
To convert .c to .i file use below command:-(suppose we have p1.c)
cc -E p1.c -o p1.i 

2) Translator:-

i)It convert the program into Assembly language
ii)It also check syntactical error
 
To convert .i file to .s file use below command :- 
cc -s p1.i -o p1.s 
3) Assembler:-

i)Convert the program in machine understandable language.
ii)Convert .s file to .o file (Op-Code)


To convert .s file to .o file use below command :- 
cc -c p1.s -o p1.o 

4) Linker:-

i) Links with in built library & adds some OS related information.
ii)Creates an executable file (a.out)


To convert .o file to binary file use below command :- 
cc p1.o -o p1