HP-UX Linker and Libraries User's Guide
$ ar tv libunits.a
rw-rw-rw- 265/ 20 230 Feb 2 17:19 1990 length.o
rw-rw-rw- 265/ 20 228 Feb 2 16:25 1990 mass.o
rw-rw-rw- 265/ 20 230 Feb 2 16:24 1990 volume.o
The next example replaces length.o in libunits.a, only if length.o is more recent than
the one already contained in libunits.a:
$ ar ru libunits.a length.o
crt0.o
The crt0.o startup file is not needed for shared bound links because dld.so does some of the
startup duties previously done by crt0.o. However, you still need to include crt0.o on the link
line for all fully archive links (ld -noshared). In PA-32 mode, crt0.o must always be included
on the link line.
Users who link by letting the compilers such as cc invoke the linker do not have to include crt0.o
on the link line.
Archive Library Location (IPF)
After creating an archive library, you can save it in a location that is easily accessible to other
programmers who may want to use it. There are two main choices for places to put the library:
• in the 32-bit /usr/lib or 64-bit /user/lib/pa20_64 directory
• in the 32-bit /usr/local/lib or /usr/contrib/lib directory
Using /usr/lib and /usr/lib/pa20_64
Because the linker searches /usr/lib or /usr/lib/pa20_64 by default, you may put your
archive libraries in /usr/lib or /usr/lib/pa20_64 and thereby eliminate the task of entering
the entire library path name each time you compile or link.
The drawbacks of putting the libraries in /usr/lib or /usr/lib/pa20_64 are:
• You usually need super-user (system administrator) privileges to write to the directory.
• You may inadvertently overwrite an HP-UX system library that resides in the directory.
Check with your system administrator before attempting to use /usr/lib or
/usr/lib/pa20_64.
Using /usr/local/lib or /usr/contrib/lib
The /usr/local/lib and /usr/local/lib/pa20_64 library typically contain libraries
created locally - by programmers on the system; /usr/contrib/lib and
/usr/contrib/lib/pa20_64contain libraries supplied with HP-UX but not supported by HP.
Programmers can create their own libraries for both 32-bit and 64-bit code using the same library
name. Although ld does not automatically search these directories, they are still the best choice
for locating user-defined libraries because the directories are not write-protected. Therefore,
programmers can store the libraries in these directories without super-user privileges. Use
-L/usr/local/lib or -L/usr/contrib/lib for 32-bit libraries, or
-L/usr/local/lib/pa20_64 or -L/usr/contrib/lib/pa20_64 for 64-bit libraries to tell
the linker to search these directories.
Creating Shared Libraries
Two steps are required to create a shared library:
1. Compile one or more source files to create object files. In PA-32 mode, it is necessary to use
the +Z compiler option to create position-independent code.
2. “Creating the Shared Library with ld” (page 99) by linking with -b.
98 Creating and Using Libraries