Example 16 Specifying library paths in PA-32 mode and IPF/PA-64 mode

The following are examples of specifying library paths in PA-32 mode and IPF/PA-64 mode (IPF

(32-bit and 64-bit) and PA-64):

Linking to libraries by fully qualifying paths. The library does not contain SONAME specified by the linker +h option when building the shared library: In this example, the program is linked with /opt/myapp/mylib.sl:

$ cc main.o /opt/myapp/mylib.sl

Perform 32-bit link.

$ cc +DD64 main.o /opt/myapp/mylib.sl

Perform 64-bit link.

At run-time, in both 32-bit and 64-bit mode, the dynamic loader only looks in /opt/myapp to find mylib.sl.

Linking to libraries using -l library or -l:library options:

In this example, the +s option is not explicitly enabled at link time. Both 32-bit and 64-bit versions of a shared library called libfoo.sl exist in the default location.

PA-32 and IPF 32-bit mode example: $ cc main.o -lfoo -o main

Perform 32-bit link.

With the +DD32 default, when linked in PA-32 mode, main aborts at run time if libfoo.sl is moved from /usr/lib. This is because the absolute path name of the shared library /usr/lib/libfoo.sl is stored in the executable.

When linked in IPF 32-bit mode, main does not abort at run time if libfoo.sl is moved from /usr/lib/hpux32 as long as LD_LIBRARY_PATH or SHLIB_PATH is set and point to libfoo.sl.

PA-64 and IPF 64-bit mode example: $ cc +DD64 main.o -lfoo -o main

Perform 64-bit link.

When linked in IPF or PA-64 mode, main does not abort at run time if libfoo.sl is moved, as long as LD_LIBRARY_PATH or SHLIB_PATH is set and point to libfoo.sl.

Linking to libraries using -Land +b path_list:

The -Loption is used by the linker to locate libraries at link time. The +b option is used to embed a library path list in the executable for use at run time.

PA-32, IPF 32-bit mode example:

$ cc main.o -L. -Wl,+b/var/tmp -lme

Link the program.

$ mv libme.sl /var/tmp/libme.sl

Move libme.sl. $ a.out

Run the program.

Dynamic Path Searching for Shared Libraries 85

Page 85
Image 85
HP UX Software Transition Kit (STK) manual Perform 32-bit link