C Compilation Model and Processes

How do you compile C code? How do you make executable programs from C source code files? This tutorial outlines the basic C compilation model and processes that address those questions. You will have a better understanding of how to make the executable file from C source code files.

The following picture illustrates the C compilation model.

c compilation model


Let’s examine each component in more detail.

  • The input of the C compilation process is C source code file and its result is an executable file. The output of the previous component is the input of the next component.
  • The preprocessor uses the source code as input. The preprocessor is in charge of removing all the comments and interpreting preprocessor directives indicated by the hash # sign. For example in the hello world program, the #include directive is used to include code of the corresponding file e.g., standard I/O file, stdio.h. The preprocessor will include the source code in the stdio.h file in the main program before transferring it to the compiler.
  • After preprocessor processing the source, it transfers the result to the C compiler. The C compiler is responsible for translating from plain source code into assembly code. We are using gcc compiler to translate C code into assembler code.
  • The assembler is in charge of creating object code. On Windows systems the object code files have .obj extension and on UNIX systems the object code file has .o extension.
  • If in the source code file, you use functions from a library, the link editor will combine these functions with the main() function to make an executable file of the program. The link editor sometimes is also known as the linker.

The compilation process seems to be lengthy. It takes time and requires more efforts if you compile a program yourself. However, with a good IDE like CodeBlocks, you can configure all the components once and the IDE will handle the tasks for you automatically with a push of a button.

If you want to use a different C compiler to make C program works on a specific platform, you can check it out the Wikipedia, C compilers list page.