All the steps of C compilation — Learned the Holberton way

Rodrigo Zarate Algecira
2 min readJun 18, 2021

No previous knoweledge of C but some of PHP and Javascript were the background, been able to understand the steps of C compilation it’s a mayor goal because it tooks me just ¡ONE DAY!

Photo by Christina Morillo on Pexels

First things first

You have to know a few things before start:

  • How to use a command line (like Terminal)
  • What are good standards in codding
  • How to read bunch of documentation fast

So what happens when you type gcc main.c?
As far as I can tell there are 4 main steps involved in the process of compiling a C file:

Preprocessor

The preprocessor receives the .c file as input and send the output to the compiler.

  • Removes comments (as they are for developers) the lines between /** and */
  • Inserts the code asked by the includes. The files with .h extention
  • Replace macro names with code
The code before the preprocessor

So the code ends looking like this in this step

The code after the preprocessor

compiler

The compiler takes the output of the preprocessor and creates Assembly code, a set of code lines out of nemonic english words

Assembler

The assembler receives the Asembly code and creates Object code, a set of code lines out of ceros and letters in several files.

Linker

The linker takes the Object code and use Libraries to create executable files. This kind of code is known as machine code.

The exe file generated is the compiled C program

How do you compile in Linux?

The standard compiler of the Linux based systems is gcc that stands for GNU Compiler Collection and it is mainly used to compile the C and C++ programs, gcc have a lot of flags that allow users to decide the kind of output in such way that you can control and debug the develop process.

¡Thats it!

--

--

Rodrigo Zarate Algecira

In the path of Programming #AgriculturaUrbana $rodrigozarate Instagram: agromerlin