Hidoussi Abderrahmen
2 min readJun 10, 2020

--

What happens when you type gcc main.c ?

So what is gcc ? , gcc is stands for GNU Compiler Collection which are free-softwares and mass-collaboration projects launched by Richard Stallman in 1983 which offered developers to have access to powerful tools for free.

And as one such tool gcc is a completely free and one if not the go-to compiler for most Unix-like operating systems for C programing language .

So how does it work exactly ? well to start off lets suppose you have written a simple C source code in a file under the name of “main.c” , to get from the “main.c” file to the executable file the compiler will go through 4 steps :

Step 1 : The preprocessing

The compiler will get rid of the comment in your source file “main.c” , include all the header files (usually <file/lib-name.h>) and replace most named variable with their values .

and you can specifically stop the compiler gcc exactly after this step by using the option “gcc -E” .

Step 2 : The compiling

At this step the compiler will generate an IR code which stands for Intermediate Representation from the preprocessed file

and as with the previous step you can stop the compiler gcc exactly after this step by using the option “gcc -S” .

Step 3 : The assembling

At this step the compiler will take the IR code and turn it into binary sequence .

and as with the previous step you can stop the compiler gcc exactly after this step by using the option “gcc -c” .

Step 4 : The linking

This is the part where the compiler links your source code with the header libraries to produce one wrapped up package of output.

--

--