12.1 – Build process or Compiler Chain

by subbu on December 14, 2017

Building process of a C program

Before discoursing preprocessor, let us have a look on total build process.
The code written in C language is called the source code. It is saved with .c extension (prog.c).

A program called preprocessor process the source code before compilation of the program. Because the compiler is called processor, the program which processes the code before compilation is called preprocessor. The preprocessor generates the expanded source code or intermediate code, which is saved with .i extension (prog.i)

The expanded source code is then sent to the compiler. Debugger is a part of compiler, which identifies the errors and warnings if any. If the expanded code is error-free then the compiler generates the assembler source according to the machine, which is saved with .s or .asm extension (prog.s/prog.asm)

The assembler then converts the assembler source into object code, which is saved with either .o or .obj extensions. In case of Linux it is .o and in case of turbo C it is .obj (prog.o/prog.obj). The object code is also called relocatable object code because only relative addresses (not exact addresses) of different memory segments are set here.

As the final step, the linker links the runtime support library to the object code and generates executable or machine code according to the local platform, which is saved with .exe extension (prog.exe). It is the actual build, which can be copied on to any other machine and used as software.

build process in C

Once the executable file is created and stored on the hard disk then it would be ready to execute. Once we start the program then the .exe file is first brought into the RAM by an operating system component called Program Loader. Now exact positions to memory segments are set and execution starts from the first statement.

All the tools used to generate build like debugger, preprocessor, compiler, assembler and linker are together called compiler chain.
In coming sessions, we will discourse how we can generate expanded or intermediate and assembly source code in different environments like Windows and Linux.

Previous post:

Next post: