What happens when you type gcc main.c

Moonage Volkova
2 min readFeb 3, 2021

--

First of all, we need to know what gcc exactly is to explain this command.

GCC COMPILER

GCC is an integrated compiler of the GNU project for C, C ++, Objective C and Fortran; it is capable of receiving a source program in any of these languages ​​and generating a binary executable program in the language of the machine where it is going to run.
The acronym GCC stands for “GNU Compiler Collection”. Originally it stood for “GNU C Compiler”.

So...what happens when you type gcc main.c?

To answer this, we are going to use an example code, writing this inside of main.c and then run gcc main.c.

#include <stdio.h>

/**
* main - Entry point
*
* Return: Always 0 (Success)
*/
int main(void)
{
return (0);
}

This code (gcc main.c) follows the process shown below when running:

  1. Preprocessing.
  2. Compilation.
  3. Assembling.
  4. Linking.
C compiler process

Preprocessing:

It is a stage when the compiler takes the source code and removes all of its comments that are indicated by a # or /**/.s. The program is set up to be examined.

gcc -E main.c

Compiling:

Here, the computer translates the source code into an assembly language.

gcc -S main.c

Assembling:

In this part, the assembly code generates before it’s going to be converted.

gcc -c main.c; cat main.o

Linking:

Object files that are linked together generate an executable file and gcc will create the output as an executable file called “a.out”.We use ls to see if a.out is there and that means the proccess is correct.

ls 
a.out file in the list.

And that’s it! hope you understand this blog.

--

--