Because this section tries to cover the widest possible audience,
it may provide more
background than many users will need to link their
programs with a C language library.
If you are interested only in the how-to, and are comfortable
with a purely formal presentation that scants motivation
and background alike, you may want
to skip to
the quick-reference guide
in the last subsection.
Link editing refers to the process in which a symbol
referenced in one module of your program is connected
with its definition in another -- more concretely, the process by which
the symbol printf() in
our sample source file hello.c
is connected with its definition in the standard C library.
Whichever link editing model you choose, static or dynamic,
the link editor will search each module of your program,
including any libraries you have used, for definitions of undefined
external symbols in the other modules.
If it does not find a definition for a symbol,
the link editor will report an error by default,
and fail to create an executable program.
Multiply defined symbols are treated differently, however,
under each approach.
For details, see
``Multiply defined symbols''.
The principal difference between static and dynamic
linking lies in what happens after this search is completed:
Under static linking, external references in your program
are connected with their definitions -- assigned addresses
in memory -- when the executable is created.
If the object code is in an archive library,
copies of the archive library object files that satisfy
still unresolved external references in your program
are incorporated in your executable at link time;
if the object code is in a static shared library,
a special section called .lib
that identifies the library code is created in the object file
and the required shared library code is brought into the address space of the
process only at the time the resulting a.out file is executed.
Under dynamic linking, the contents
of a dynamically linked library are mapped into
the virtual address space of your process at run time.
External references in your program
are connected with their definitions when the program is executed.
This section examines the link editing
process in detail.
It starts with the
and with the basics of
linking your program with the standard libraries
supplied by the C compilation system.
It then details the
implementation of the dynamic linking mechanism,
and looks at some
for development of dynamically linked libraries.
It also considers the
reasons why you might prefer dynamic to static linking,
Dynamically linked programs save disk storage and system
process memory by sharing library code at run time.
Dynamically linked code can be fixed or enhanced without having to
relink applications that depend on it.
Linking with archive libraries
Optimizing your program
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003