What happens when you type gcc main.c

Renzo Perez
1 min readFeb 4, 2021

--

Why do we need to compile a program?

What is a Compiler?

A compiler its a program that translates an hight level language into a machine language (combinations of 0s and 1s), this process its called compilation.

In the overview level compilation process can be separated into 4 diferent stages

Pre-Processor

In this step it verifies the following

-All the lines in your code starting with the pound (#) character which is known as macros or #define directives.

-Expands included files

-Ignores comments

To stop the gcc compiler at the end of this step we do

gcc -E [ File.c ]

Compiler

Takes the output of the preprocessor and generates assembly language

To stop the gcc compiler at the end of this step we do

gcc -S [ File.c ]

Generating a File.s file

Assembler

In this step the code its converted into 0s and 1s

To stop the gcc compiler at the end of this step we do

gcc -c [ File.c ]

Generating a File.o file

Linker

This is the last step it merges all the object code from multiple modules into a single one and add the library functions if we are using some

--

--

Renzo Perez
Renzo Perez

No responses yet