DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Shared libraries

What is a shared library?

A shared library is a file containing object code that several a.out files may use simultaneously while executing. When a program is link edited with a shared library, the library code that defines the program's external references is not copied into the program's object file. Instead, a special section called .lib that identifies the library code is created in the object file. When the UNIX system executes the resulting a.out file, it uses the information in this section to bring the required shared library code into the address space of the process.

The implementation behind these concepts is a shared library with two pieces. The first, called the host shared library, is an archive that the link editor searches to resolve user references and to create the .lib section in a.out files. The structure and operation of this archive is the same as any archive without shared library members. It must be present on the system when the a.out files are link edited.

The second part of a shared library is the target shared library. This is the file that the UNIX system uses when running a.out files built with the host shared library. It contains the actual code for the routines in the library. It must be present on the the system where the a.out files will be run.

A shared library offers several benefits by not copying code into a.out files. It can:

At run time shared library code is brought into the processes' address space. Therefore, updating a shared library effectively updates all executable files that use the library. If an error in shared library code is fixed, all processes automatically use the corrected code.

Non-shared libraries cannot offer this benefit: changes to archive libraries do not affect executable files, because code from the libraries is copied to the files during link editing, not during execution.

Shared libraries examples

The C and networking libraries are available as shared libraries.

Shared Host Library Target Library
Library Command Line Option Pathname
C Library -lc_s /shlib/libc_s
Networking Library -lnsl_s /shlib/libnsl_s
The _s suffix is used to indicate that the library is shared and statically linked.


Next topic: Building an a.out file
Previous topic: Shared libraries

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