The translation is performed by the compilation system in the sequence of four phases:
- Preprocessor – Preprocessing
- Compiler – Compiling
- Assembler – Assembly
- Linker – Linking
Preprocessor will read the source file and do following actions:
- Removes comments.
- Macro expansion.
- Expanding included files.
When the compiler process the source file HelloWorld.c, it will generate a text file with .i extension.
You can get this file by using following command:
gcc -E HelloWorld.c -o HelloWorld.i
Compiler takes the output of the preprocessor and translates the file into assembly language, it also checks the C language syntax for errors.
It will generate a text file with .s extension. You can get this file by using following command:
gcc -S HelloWorld.i -o HelloWorld.s
Assembler takes the output of the Compiler and translate it into low-level machine code.
It will generate a binary file with .o extension. You can get this file by using following command:
gcc -c HelloWorld.i -o HelloWorld.o
Linker takes the output of Assembler and merges all the object code from multiple modules into a single one.
It will generate the target executable file.
gcc HelloWorld.o -o HelloWorld
The four steps of compilation are: preprocessing, compiling, assembly, linking.
They are owned by Preprocessor, Compiler, Assembler, Linker in compilation system.