Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

11.5 The linker

The final stage of compilation is the linking of object files to create an executable. In practice, an executable requires many external functions from system and C run-time (crt) libraries. Consequently, the actual link commands used internally by GCC are complicated. For example, the full command for linking the Hello World program is:

$ ld -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o 
 /usr/lib/crti.o /usr/lib/gcc-lib/i686/3.3.1/crtbegin.o 
 -L/usr/lib/gcc-lib/i686/3.3.1 hello.o -lgcc -lgcc_eh
 -lc -lgcc -lgcc_eh /usr/lib/gcc-lib/i686/3.3.1/crtend.o 
 /usr/lib/crtn.o

Fortunately there is never any need to type the command above directly--the entire linking process is handled transparently by gcc when invoked as follows:

$ gcc hello.o 

This links the object file 'hello.o' to the C standard library, and produces an executable file 'a.out':

$ ./a.out 
Hello, world!

An object file for a C++ program can be linked to the C++ standard library in the same way with a single g++ command.


 
 
  Published under the terms of the GNU General Public License Design by Interspire