What happens when you type gcc main.c?

Hadir Jenni
2 min readSep 17, 2020
an image stand for GCC

What is the GCC?

GCC is a shortcut of ‘GNU Compiler Collection’ its’s produced by GNU project and it compiles many programming languages which : C , C++ … for a linux and GNU project so to compile a C file for example we use the command gcc filename just like this

command line

What happens when you type gcc main.c?

first (1) prepocessing:

when you type gcc main.c the compiler start interepting lines of the file main.c by that way :

it delete the comments then include codes from header (exactly from the source file)

second(2) compilation:

the output passe to compilation and gcc generates assembly code

third(3) assembly:

the assembler convert assembly code to binary code so that the computer can interpret it

fourth (4) linking :

in this step the compiler links the code with a runtime library and accept the main.o as an input and since we didn’t use any option (-o -s ..) the executable file will be saved in the default file a.out

Finally

we can execute the saved file just by typing ./a.out

schema of steps

--

--