Compilation Contemplation

A green circuitboard
Photo by Michael Dziedzic on Unsplash

Before using any C program, it is essential to first compile it. While a simple

will compile your code for you, it’s critical to understand the steps that it takes to make your program executable.

Steps of Compilation

  1. Preprocessor
  2. Compiler
  3. Assembler
  4. Linker


The preprocessor will format your program for the compiler. To do so, it removes comments, includes header files, and performs macro expansion.

To send a file to the preprocessor but not compile it, we will use this command:


The compiler takes the output from the preprocessor and turns it into assembly code.

To compile our file but not assemble it, we will use this command:

If we apply this to our main.c file, we get this output:


The assembler takes the assembly code and turns it into machine code.

To send our file through every step except for the linker, we will use this script:

if we apply this to our main.c file, we get this output:

You will notice that this gives you the file main.o. While this format is the same as a fully-compiled program, it will not be executable.


The linker combines the object code from the assembler with library code in order to produce an executable program.

To fully compile our program, we will use this command:

As you’ll notice, this command will automatically name the file for you. If you want to specify the new name of the file, use this:

You will now have an executable file!

Software engineering student and lover of mountains.