HP-UX Linker and Libraries User's Guide

These functions constitute the ELF access library (libelf) which lets a program manipulate ELF (Executable
and Linking Format) object files, archive files, and archive members. The linker searches this library if the
(3E)
-lelf option is specified. The header file <libelf.h> provides type and function declarations for all
library services (described in elf(3E).
These functions comprise the Standard input/output routines (see stdio(3S)). They are located in libc.(3S)
These functions comprise the Math library. The linker searches this library under the -lm option (for the
SVID math library) or the -lM option (for the POSIX math library).
(3M)
These functions comprise the Graphics library.(3G)
These functions comprise the Instrument support library.(3I)
Various specialized libraries. The names of the libraries in which these routines reside are documented on
the manpage.
(3X)
The routines marked by (2), (3C), and (3S) comprise the standard C library libc. The C, C++,
and FORTRAN compilers automatically link with this library when creating an executable program.
For more information on these libraries, see C, A Reference Manual by Samual P. Harbison and
Guy L. Steele Jr., published in 1991 by Prentice-Hall, or UNIX System V Libraries by Baird Peterson,
published in 1992 by Van Nostrand Reinhold, or C Programming for UNIX by John Valley,
published in 1992 by Sams Publishing. For more information on system calls, see Advanced UNIX
Programming by Marc J. Rochkind, published in 1985 by Prentice-Hall or Advanced Programming
in the UNIX Environment by W. Richard Stevens, published in 1992 by Addison-Wesley.
Caution When Mixing Shared and Archive Libraries
Mixing shared and archive libraries in an application is not recommended and must be avoided.
That is, an application must use only shared libraries or only archive libraries.
Mixing shared and archive libraries can lead to: unsatisfied symbols, hidden definitions, duplicate
definitions, and cause an application to abort or exhibit incorrect behavior at run time. The following
examples illustrate some of these problems.
NOTE: The examples in this section apply only to PA-32 compatibility mode.
Example 1: Unsatisfied Symbols
This example (in PA-32 and PA-64/IPF(+compat mode) shows how mixing shared and archive
libraries can cause a program to abort. Suppose you have a main program, main(), and three
functions, f1(), f2(), and f3() each in a separate source file. The program main() calls f1()
and f3() but not f2():
$ cc -c main.c f1.c f2.c //Compile to relocatable object code.
$ cc -c +z f3.c //Compile to position-independent code
Figure 12 Example 1: Unsatisfied Symbols: Compiling
Next, suppose you put f3.o into the shared library lib3.so and f1.o and f2.o into the archive
library lib12.a:
$ ld -b -o lib3.so f3.o Create a shared library.
$ ar qvc lib12.a f1.o f2.o Create an archive library.
118 Creating and Using Libraries