42 Chapter 2
What Happens When You Compile and Link a Program
Linking Programs on HP-UX
Linking Programs on HP-UX
The HP-UX linker, ld, produces a single executable file from one or more
input object files and libraries. In doing so, it matches external
references to global definitions contained in other object files or libraries.
It revises code and data to reflect new addresses, a process known as
relocation. If the input files contain debugger information, ld updates
this information appropriately. The linker places the resulting
executable code in a file named, by default, a.out.
In the C program example (see “Compiling Programs on HP-UX: An
Example”) main.o contains an external reference to sum_n, which has a
global definition in func.o. ld matches the external reference to the
global definition, allowing the main program code in a.out to access
sum_n (see Figure 2-3).
Figure 2-3 Matching the External Reference to sum_n
If ld cannot match an external reference to a global definition, it
displays a message to standard error output. If, for instance, you compile
main.c without func.c, ld cannot match the external reference to
sum_n and displays this output:
$ cc -Aa main.c
/usr/ccs/bin/ld: Unsatisfied symbols:
sum_n (code)