Linking

Linking is the step which takes one or more object files puts it or them together with any functions from the library and produces an executable file - a program which can be run. Remember that the object files were produced by either a compiler or an assembler. Object files contain machine language plus some additional information needed by the system.

   +---------+    ##########    +------------+
   | Object  |    #        #    | Executable |
   |         |===># Linker #===>| File,   or |
   | File(s) |    #        #    | Program    |
   +---------+    #        #    +------------+
                  #        #
   +---------+    #        #
   | Library |    #        #
   |         |===>#        #
   |  Files  |    #        #
   +---------+    ##########

Library files are a collection of object files, usually supplied with the compiler. They contain commonly used functions.

It is at the Linking stage that any variables or functions referred to in a separately compiled module will be found and assigned a place in memory. At this point, all references to such objects whose address was unknown in a module but known in another can be specified, and the object files completely filled in.

In addition to this, the linker puts instructions at the beginning of the program that is being built or linked (as it is said), which will prepare the run-time environment for use by the program. This run-time environment, besides the program and its data specified during the compilation step, also includes a stack and a heap.

The stack and heap are essential parts of the 'C' run-time environment, and will be explained in detail later. For now, the the Stack in the computer's memory is like a stack of paper on your desk. It is where you put things on top to be done (and usually) take things from the top to be worked on. The Heap is where you keep blank or unused paper (i.e. memory). You take blank paper (memory) from the Heap when you need it.


© 1991-2008 Prem Sobel. All Rights Reserved.