The GCC Compilation Process for C: A Deep Dive

Atsuki Elizabeth Rose
2 min readFeb 4, 2021

The GCC is an optimizing compiler, it stands for ‘GNU Compiler Collection” (Fun fact, GNU stands for ‘GNU’s Not Unix, because it’s design is Unix like, but differs by being free software and containing no Unix code). But what is a compiler? How does the compilation process work, and how can we understand it better? Well, that’s what this blog post is for.

A compiler basically processes your code, written in letters, symbols and numbers, and turns it into 1s and 0s, so that the computer can understand it and execute it. This is the result of several stages of the compiling process, but the main four are:

*Preprocessing
*Compiling
*Assembly
*Linking

We’ll go through these one by one, explaining what each of them do.

Preprocessing

The preprocessor takes the source code, aka the code you wrote in a text editor. The preprocessor then expands this code and removes all comments.

Compiling

This newly expanded source code is then passed to the compiler, and it converts the code into assembly code, so that the assembler can do its job next.

Assembly

It’s the assembler’s turn! The assembler takes the assembly code prepared by the compiler, and converts it into object code. It also gives it a name, which can be set by the user with the gcc -o command, but if the user didn’t choose one, the result will be a file named ‘a.out’.

Linking

The linker is the final stop in the compiling process, and it has quite the workload. All programs in C are written using what are known as library functions which are precompiled. The linker’s job is to combine the object code of the used library functions with the object code of our program, linking the library functions’ definitions so that our code can use them. Finally, it produces the executable file, named a.out by default like we mentioned, and finishes the compilation process.

--

--