GCC Compilation Process

Katherine De La Hoz
2 min readSep 17, 2020

As we know, the compilation process is a mechanism by which the source code of a program is translated into machine language. The compilation can be done in several ways, this time I will write about how to do it through the GCC compiler. The GCC compilation process is done in 4 easy steps:

1- Preprocessor: In this first step, comments are removed and header files are included in the source code, and the name of the macro is replaced with the code.

gcc -E hello.c> hello.pp

2- Compiler: At this moment the source code is translated and the assembly code is generated.

gcc -S hello.c

3- Assembler: In the assembler the assembly code is converted into an object code that would be the machine language understandable by the processor.

gcc -c hello.c

4- Linker: For the new file created to be understandable to the team, it needs to be combined with the libraries and then create an executable file. This is what the linker does.

gcc -o hello hello.c

To verify that this process works, perform the following steps:

Enter the Linux terminal.
- Create a folder called: compilation_process through the mkdir command.
- Locate yourself in the folder that you have created through the cd command
- Create a file called hello.c. Type the following into that file:

#include <stdio.h>
/ * File: Hello World * /
int main (void)
{
printf (“Hello World \ n”);
return (0);
}

Run the compilation commands in the following order:
gcc -E hello.c> hello.pp
gcc -S hello.c
gcc -c hello.c
gcc -o hello hello.c

Through the command ls -l you can verify that some files have been created in the process.

Finally run your script in the following way:
./Hello

¡ You did it, the file compiled!

--

--