Steps of compiling a C program

Bouzouitina Hamdi
3 min readFeb 5, 2020

--

GNU Compiler Collection

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain and the standard compiler for most projects related to GNU and Linux, including the Linux kernel. The process can be broken down into four steps: Preprocessing, Compiling, Assembling, and Linking.

We can walk through the steps with this program :

Step 1: Preprocessor

The C preprocessor or cpp is the macro preprocessor for the C and C++ computer programming languages. The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control. For example, #include <stdio.h> will be replaced with contents in the stdio.h header file.

To print the result of the preprocessing stage use :

Using the -o option will allow us to specify the name of our output file.

Step 2: Compiler

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain and the standard compiler for most projects related to GNU and Linux, including the Linux kernel.

The C compiler will convert the preprocessed source code into assembly code(.s extension).

To print the result of the compiling stage use :

Step 3: Assembler

The GNU Assembler, commonly known as gas or simply as, its executable name, is the assembler used by the GNU Project. It is the default back-end of GCC. It is used to assemble the GNU operating system and the Linux kernel, and various other software. It is a part of the GNU Binutils package.

The assembler then takes the assembly code and converts it into a binary representation of our program ( .o extension in UNIX systems).

To print the result of the assembling stage use :

Step 4: Linker

These options come into play when the compiler links object files into an executable output file. They are meaningless if the compiler is not doing a link step.

In the Linking step, multiple object files will be linked together to create one executable.The will locate and include the associated code into the final output file.

--

--

No responses yet