Last revision August 4, 2004
|Table of Contents|
Basic procedure to produce executable programs in compiled languages
Write your program in the source language and save in disk files.
You usually save one routine per file.
Fortran routine files should have a name that ends with .f (or .F if you want to include compiler preprocessor macro statements like #include or #define).
C routine files should have a name that ends with .c.
Often, it is useful to put code that defines data structures or parameters into a separate file that can then be included by any routine that needs these structures or definitions. Such "include" files should have a name that ends with .h.
Compile each routine to create the "object" code module and store on disk.
A preprocessor to the compiler first finds necessary include files and inserts them, and expands macro definitions.
The compiler itself translates your source into the machine language, but cannot resolve all references to other routines or shared data structures.
You can optionally request that the code be "optimized", which makes the final program run faster at the expense of possibly being more difficult to debug errors.
Another option requests that symbol table information be created for the debuggers.
Object code modules that you plan to re-use for several different programs can be combined into a single indexed disk file called a "library" with the ar and ranlib programs.
Link all the necessary object code modules together into an executable program.
The link step resolves all address references to other routines and shared data structures.
Every program requires some "system" routines for I/O, math functions, etc. The linker searches the standard system object code libraries to find these and add them in. On many modern Unix systems, such as pangea, these system routines are not directly added in to your program. Instead, a "stub" that references the appropriate system routine is added. When the program executes, the kernel can use that "stub" to find the system routine to load. Actually, it can share the same copy of that routine in memory among many programs. This method of "shared libraries" saves both disk space and memory.
You can also specify special or private object code libraries to be searched for any missing routines, for example, the library containing the LINPACK mathematical routines.
System routines can differ from language to language, so rather than using the linker directly, we usually invoke it from the compiler for the language we are using, which then passes along appropriate information to the linker about which libraries to use.