1.5.2 Linking

Strictly speaking, the assembler outputs binary code that can be understood by the processor. However, the file format of the output of the assembler is not suitable for the operating system to load into memory and start execution. In addition, there may be multiple source files, each referring to labels defined in other files.

A linker, ld, is used to resolve references of labels and output a single file that is suitable for the operating system to execute. For our purpose, the following command is sufficient:

ld -o test.out test.o

In this command, the option -o test.out tells the linker to output an executable file called test.out. The debugging information in test.o is automatically incorporated into the executable file.

After this step, you can use the following command to verify the existence and size of the executable file:

ls -l test.out



Copyright © 2009-04-16 by Tak Auyeung