C Source Code Compilation Process
C Source Code Compilation Process
1. Pre-processing,
2. Compiling,
3. Assembling, and
4. Linking
The compiler checks the source code for any syntax or structural
errors and after checking, if the source code is found error-free, it
then generates the object code that has an extension .obj (for
Windows) or .o (for Linux).
Let us now take a look at the different stages of the compilation
process in the C language.
Compilation Process
Pre-processing
Compiling
Assembling
Linking
Step 1: Preprocessor
1. #include
To include a particular header using the name of the header file into
the C language program code.
2. #define
Just like the above three, there are many other preprocessors, we
will cover them in detail in a separate tutorial.
Step 2: Compiler
The source file which got the (.i) extension in the previous step gets
converted into (.s) extension by the compiler.
Step 3: Assembler
The assembler converts the assembly code that it gets from the
compiler into the object code. The extension of the file in this step
becomes (.obj).
Step 4: Linker
If your C program includes a header file, and you are using some
function defined in that header file, then the Linker will link the
required object code for the function in the library, to the object
code of your program and package them together.
Similarly, if your program code is too big and you break it into two
files, then both the source code files will be converted into object
code separately and then the Linker will link them and make the
code ready for execution. This is also called Separate Compilation.