Katherine Soto

Feb 4, 2021

3 min read

Compilation in .c : What happens when you type gcc main.c?

First, we need to know the 4 steps of C compilation process

Components of Compiler
  1. Preprocessor: Remove comments and include header files in source code, replace macro name with code

2. Compiler: Generate assembly code

3. Assembler: Convert assemble code into object code (the output is in binary)

4. Linker: Links with the libraries, codes and create an executable file, For example with a libraries.h + functions.c + main.c

Now let’s check a graphical example of a file compiling step per step in .c:


What is gcc?

GNU Compiler Collection”. GCC is an integrated distribution of compilers for several major programming languages. In language c, we will use ggc to compile our archives.

How we can use gcc?

We can use in different forms depending of what we want. You can search the commands that we need to add to gcc typing:

gcc - - help
manual that will appear when you use gcc — — help


  1. You want run ony the preprocessor for the file test.c
  • First go to your manuall (gcc - - help) and search the option to preprocessor (-E)
  • Then use with gcc
gcc -E test.c

2. And what happen if you want that the output of the file name will be: result

  • Again, search in your manual and you will find “-o” . So add your “-o” before of the file that you want to apply. In this case, before “result” because, you want to create this file
gcc -E test,c -o result

3. Finally, let’s check one more example:

Advanced problem of the day: 101-quote.c

You can see that after compiling with

gcc -Wall 101-quote.c

it’s generate an automatic file a.out, and when we executed with:


the program that we write inside of 101-quote.c runs, in this case is printing a phrase.

Now, you are an expert in gcc :) thank u for reading this post, you are amazing :D