C compilation system

Linking with archive libraries

An archive library is a collection of object files. Each function, or small group of related functions (typically, the related functions that you will sometimes find on the same manual page), is stored in its own object file. These object files are then collected in archives that are searched by the link editor, ld(CP), when you specify the necessary options on the cc command line. The link editor makes available to your program only the object files in these archives that contain a function you have called in your program.

The cc command line:

cc file1.c file2.c file3.c

creates object files corresponding to each of your source files, and links them with each other to create an executable program. These object files are called relocatable object files because they contain references to symbols that have not yet been connected with their definitions -- have not yet been assigned addresses in memory.

Ideally, this command line would arrange for the standard C library functions that you have called in your program to be linked with your executable automatically. The standard C library is, in this default arrangement, an archive library called libc.a, which means that the functions you have called are linked with your program at link editing time. The standard C library contains system calls and C language functions. See ``C library (libc)'' for details.

Under the default arrangement, the cc command creates and then links relocatable object files to generate an executable program. Copies of the object files in libc.a that resolve still unresolved external references in your program are incorporated in your executable at link time. If you are satisfied with this arrangement, you need make no other provision for link editing on the cc command line.

The next section, shows you how to dynamically link your program with the dynamically linked library version of libc to override the static linking default.

Next topic: Linking with dynamically linked libraries
Previous topic: Link editing

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003