In the above example, if you type:

$ ld main.o -L. -lbar -lc $ mv libme.so /var/tmp

instead of:

$ mv libme.so /var/tmp

$ ld main.o -L. -lbar -lc

the linker finds libme.so in ./ at link time, and the dynamic loader finds libme.so in /var/tmp at run time. At run time, the dynamic loader searches paths to resolve external references made by main in the following order:

1. ./libc.so not found /usr/lib/hpux32/libc.so found

2.SHLIB_PATH to find libbar.so not found

3. ./libbar.so (./libbar.so) found

4.LD_LIBRARY_PATH to find libme.so not found

5.SHLIB_PATH to find libme.so not found

6./var/tmp/libme.so found

7.LD_LIBRARY_PATH to find libc.so not found

8.SHLIB_PATH to find libc.so not found

9.LD_LIBRARY_PATH to find libbar.so not found

Library Example: Linking to Libraries with +b path_list in PA-32 Mode

This example is the same as “Library Example: Linking to Libraries with +b path_list in IPF/PA-64 Mode” (page 134), but this time the program is compiled in PA-32 mode.

$ cc -c +DD32 me.c bar.c main.c $ ld -b me.o -o libme.so

$ ld +compat -b bar.o -o libbar.so -L. -lme +b /var/tmp \PA-32 mode library created $ ld main.o -L. -lbar -lc

$ mv libme.so /var/tmp

When linking main.o, the link order is: 1. ./libbar.so found

2. ./libme.so found

3. ./libc.so not found

4./usr/lib/libc.so found In the above example, if you type:

$ mv libme.so /var/tmp

$ ld main.o -L. -lbar -lc

instead of:

$ ld main.o -L. -lbar -lc $ mv libme.so /var/tmp

the linker issues the following error message:

ld: Can't find dependent library ./libme.so Fatal Error

The linker does not look in /var/tmp to find shared libraries because in PA-32 mode the directories specified by +b pathname are only searched at run time. Because libme.so is specified with the -loption, it is subject to dynamic path searching. At run time, the dynamic loader looks for shared libraries used by main in the following order:

1. ./libbar.so found

2./var/tmp/libme.so found

3./libc.so not found

4./usr/lib/libc.so found

Using Shared Libraries in Default Mode 135

Page 135
Image 135
HP UX Software Transition Kit (STK) manual Above example, if you type, Instead, Shlibpath to find libbar.so not found