Compiling process in C

Compiling process in C

Compilation is the process of converting code written in a programming language to machine code. During this process, the code goes through different steps depending upon the compiler and language. We will explore the compilation steps in C with the gcc compiler.

1: Preprocessor.

The source code goes through the preprocessor, which removes the comments and replaces the include header files with the actual content of the header file.

The command to see the preprocessed code is

gcc -E code.c
        


2: Compiler.

The code, now expanded by the preprocessor, is passed to the compiler. The compiler converts this code into assembly code.


3: Assembler.

The compiler will convert the preprocessed code into assembly code. The assembly code is the code written in assembly language.

The command to generate the assembly code is:


gcc -S code.c
        


4: Linking.

In this step, our assembly code is linked with the other code we are using. For example, if we are using printf function our object code will be linked with the object code for printf or rather the library code containing printf and an executable will be created.

To create the final executable use


gcc code.c
        


In summary:

gcc -E code.c # generates preprocessed code
gcc -S code.c # generates assembly code
gcc -c code.c # generates object code
gcc code.c    # generates linked object code        



To view or add a comment, sign in

More articles by Nicolle Shiskobcki

  • Internet of Things - IoT

    The Internet of Things describes the objects that are embedded with sensors, software and other technologies for the…

    1 Comment
  • Python3: Mutable, Immutable... everything is object!

    In this blog I will talk about objects in Python (both Mutable and Immutable), how differently does Python treat them…

Explore content categories