• admin@embedclogic.com

C Compilation Stages

To understand the compilation process let’s create a project with the name project_name and suppose this project has 2 files-

  1. File_name1.c
  2. File_name2.c

There are 4 stages involved in the creation of executable file project_name.exe from these source files.

  1. Pre-processing
  2. Compilation
  3. Assemble
  4. Linking

1. Pre-Processing

It is the first stage when we give build command.At this stage, Two main task is performed-

  1. Elimination of Comments.
  2. Expand all the files and statements lead by #.For example, include files and macros.

File_name1.c ———-Converted into———> File_name1.i

File_name2.c ———-Converted into———> File_name2.i

2. Compilation

At the 2nd stage,

File_name1.i ———-Converted into———> File_name1.s 

File_name2.i ———-Converted into———> File_name2.s 

The compiler creates assembler file(.s) which has some sets of instructions and handed over to assembler.

3. Assembler

At the 3rd stage,

File_name1.s ———-Converted into———> File_name1.o 

File_name1.s ———-Converted into———> File_name1.o 

At this stage, all the assembly instructions of each file converted into machine code.

4. Linker

At this stage,

Executable Creation

All the linking work is done to functions and creates an executable file.