Image credit: WeGraphics

# Program Compilation - An introduction

As we already know the compilation process involves four steps,

• Pre-processing the source file
• Compiling the source file to assembly
• The assembly code is assembled to the object code
• Linking the object code with libraries

So the actual compilation process goes like the following:

$gcc -E prog.c > prog.i # pre-process$ gcc -s prog.i      # assemble
$as -o prog.o prog.s # compile$ ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 \
/usr/lib64/crt1.o \
/usr/lib64/crti.o \

The options to ld specify that our object code should be dynamically linked and the dynamic linker to be used is ld-linux-x86-64.so. The rest of the object files are C run time code that gets compiled into the object code. This is where the _start comes into out object file. Every C program has a start up code compiled in unless you explicitly say not to link start up code to the compiler. Details about the C run time routines will be given in later in this article.