What are the compilation stages in c and it's commands
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
- Preprocessor stage
- Translator stage
- Assembler stage
- linker stage
Preprocessor stage
Preprocessor is the 1st stage of compilation stage
Works of pre-processor
There are 4 works of preprocessor
- Header file inclusion
- comment removeable
- macros replacement
- 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
- Convert c program to Assembly
- 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
- 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
- Responsible for linking with libraries
- add operating system information
- generate executable code
Code to compile Translator stage
cc File_name.o