What are the compilation stages in c and it's commands

27 Dec 2022 Balmiki Mandal 0 C Programming

Compilation Stages in C and Their Commands

Introduction

Understanding the compilation process in C is crucial for every programmer. It's the process where your human-readable source code is transformed into machine-executable instructions. This page will walk you through the various stages of compilation and the commands you'll need to use.

There are 4 compilation stages in c programming

  1. Preprocessor stage 
  2. Translator stage
  3. Assembler stage
  4. linker stage

Preprocessor stage 

Preprocessor is the 1st stage of compilation stage 

Works of pre-processor

There are 4 works of preprocessor 

  1. Header file inclusion
  2. comment removeable
  3. macros replacement
  4. conditional compilation
Input of preprocessor is    .c
output of preprocessor is   .i

Code to compile preprocessor stage

 cc  -E  File_name.c  -o  File_name.i 

Note: This stage means it is ready to translate or ready to assembly

2. Translator stage:

it is a compilation of second Stage

Works of Translator 

There are two works of Translator

  1. Convert c program to Assembly
  2. Check Syntax Error
Input of Translator is       .i
output of preprocessor is   .s

Code to compile Translator stage

 cc  -S  File_name.i  -o  File_name.s 

3. Assembler stage:

it is a compilation 3rd  Stage

Works of Assembler

There are one work of Translator

  1. Convert Assembly to upcode
Input of Translator is       .s
output of preprocessor is   .o

Code to compile Translator stage

 cc  -C  File_name.s  -o  File_name.o 

4. Linker stage:

it is a compilation 4th Stage(final stage of compilation)

Works of Linker

There are Three works of Translator

  1. Responsible for linking with libraries
  2. add operating system information
  3. generate executable code

Code to compile Translator stage 

cc  File_name.o 

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.