Open Source‎ > ‎Compilation Phases‎ > ‎


The linking step is usually done with the help of ld. ld combines a number of object and archive files, relocates their data and ties up symbol references. ld normally accepts the names of different object files as input and combines them to create executable file. In the process of combining the object files, linker would combine the data and text sections of the object files, calculates the addresses of different symbols (such as printf) and replace their relative addresses with the absolute addresses.

Normally when a programmer includes a system header file such as printf, several other symbols (variables and functions) are also included with that header file. These symbols are distributed in several different libraries. Therefore the programmer ends up in providing names of million and a half object files as parameters to the linker e.g. to create a output file the linker has to be invoked with the following parameters

ld /usr/lib/gcc-lib/i386-redhat-linux/2.96/collect2 
-m elf_i386 
-dynamic-linker /lib/ 
/usr/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o i
-o test

Fortunately, gcc comes to the rescue and can resolve the required libraries for the standard header files. The output file can be created using gcc in the following way :

gcc test.o -o test