- publishing free software manuals
An Introduction to GCC - for the GNU compilers gcc and g++
by Brian J. Gough, foreword by Richard M. Stallman
Paperback (6"x9"), 144 pages
ISBN 0954161793
RRP £12.95 ($19.95)

"An excellent introduction... fills a much-needed niche in the marketplace" --- Association of C and C++ Users book review (Issue 16-4, August 2004) Get a printed copy>>>

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 

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.

ISBN 0954161793An Introduction to GCC - for the GNU compilers gcc and g++See the print edition