What happens when you type `gcc main.c` in the terminal

Francisco Guzmán Herrera
3 min readJun 11, 2020

To begin we must bear in mind that this script is divided into two partsgcc what is a command and main.c which is a file that contains the language C code we know that it is C language due to its extension .c .

GCC (GNU Compiler Collection)

As its name implies it is a collection of compilers and it supports several languages: C, C ++, Objective C, Chill, Fortran, Ada and Java.

It was produced by the GNU project and basically what it does is it takes the code that we understand and write and transforms it into the binary language that computers understand.

What happens when we run gcc main.c

As we see in the image first we list the content of our directory with ls and in the second line it shows us the content, then we executegcc main.c In the third line, by doing it as we saw before, it will transform our code into the language that your computer understands, by enumerating the content again with lswe see an executable file called a.out this is the file that runs our code and if you type less a.out You will see that it is very different from the code you had in your filemain.c it will look something like this:

Our main.cfile contains this:

As you can see it’s quite a big change.

Processes done by the `gnn` command

This command to do its job of transforming the code to binary performs 4 main processes.

The preprocessor is in charge of preparing the code to be compiled by removing for example the comments.

The compiler takes the code thrown at it by the preprocessor and generates an assembly code that only the computer can read but cannot execute since, as we said, it only understands or runs in binary.

Assember converts that code back to object code.

And the Linker will link that object code with the libraries to be able to generate the executable file in binary

Link to see a more detailed video: https://www.youtube.com/watch?v=VDslRumKvRA

--

--