Steps of Compilation

Mia Morton
2 min readFeb 7, 2019

--

What happens when you type gcc main.c?

C Compilation Process

Understanding the Compilation process in C programming language helps the programmer to better understand how the executable files are created. A programmer can halt the process at certain levels if need be. If something requires a file to be stored in assembly code; the compilation of the source code could be stopped just after it reaches the assembler.

The Compilation

Step One: Pre Processor
Create source code in a code editor (emacs or vi for example). The source code should be organized and easy for other programmers to understand. Use comments to provide details and information regarding the purpose of the source code. As part of the process pre processor removes the comments, includes source header in code and replaces all macro names with their values.

Step Two: Compiler
Pre-processed code enters the compiler. The compiler generates assembly code using mnemonics. The assembly code is a code the assembler can read.

Step Three: Assembler
The Assembler converts the assembly code into objects code. The object code is binary or machine language. Machine language is a code the linker can read and process. If a programmer wanted to store the code in assembly language the programmer would stop the process here and redirect the code to be stored in a file. We will continue on.

Step Four: Linker
At this stage, the Linker is able to take the machine language and link it to any references the code may call from the libraries referenced in the code and available to the linker. The Library, in this case, contains function code. Linker will decide which functions from the library are necessary and useful to covert the code into an executable file.

Once the source code has been turned into an executable file the compilling process is done.

--

--