The step by step of gcc =)

Ronaldaguirre
3 min readJun 11, 2020

a little confusing right? but don’t worry, we’ll understand it together !!

take the: Internet

One way to better understand things is to compare it or make some similarities with reference to what we want to learn, so I want to start by telling you that it is a compiler and why we have to use it.

As human beings we can communicate by means of sign words or many other natural expressions of the human being, but the machines? how do they communicate?; It is a very interesting and interesting question to answer.

Computers in their way of understanding what we as humans want to communicate, is in a binary way, where it reconnects [011010101], that is how machines or computers understand us.

that is why compilers are born, they are tools that help us humans to convert letters, numbers and characters to binary numbers that are finally interpreted by the machine.

For this to happen and become a language that the machine can understand, a process called compilation must be carried out, which in turn have different steps that we will learn about below.

Preprocessor

$ gcc main.c

we can see that we are preprocessing the document “main.c”

What the code actually does in this phase is request that the standard header files be included, as in this case #include <stdio.h> to our source file, it means that in the preprocessing the files are expanded and merged within the source file to produce a transient source file

Compilation

in the compilation the preprocessed file is taken and an intermediate compiled file is generated, which is produced as an assembly code where it already depends on the machine.

we have an option that if gcc is used with “-S”, the preprocessed C source code is converted into assembly language

$ gcc -S main.c -o main.s

Assembly

now we only have one step left and that is to get our code to be transformed into binary code, and for this we use an assembly

and for this use the -c option, with gcc and so the assembly language would be converted to machine language

$ gcc -c main.c -o main.o

Linking

with the assembler you leave the address of all the external functions that are called

and the executable is produced

and runs with “./”

and this is how the whole process “gcc” performs so that our programs can be run and work !!

--

--