Kenwood HP 9000 Personal Computer User Manual


 
Chapter 5 191
Creating and Using Libraries
Using Shared Libraries in 64-bit mode
Library Example: Linking to Libraries with +b path_list in
64-bit Mode.
In this example, the program main calls a shared library
routine in libbar.sl. The routine in libbar.sl in turn calls a routine
in the shared library libme.sl. The +b linker option indicates the
search path for libme.sl when linking libbar.sl. (You use +b
path_list with libraries specified with the -l library or -l:library
options.)
cc -c +DD64 me.c
ld -b me.o -o libme.sl
ld -b bar.o -o libbar.sl -L. -lme +b /var/tmp
mv libme.sl /var/tmp
ld main.o -L. -lbar -lc
In 64-bit mode, the linker finds libme.sl in /var/tmp because the +b
/var/tmp option is used when linking libbar.sl. Since -lme was
specified when linking libbar.sl, libme.sl is subject to run-time
dynamic path searching.
When linking main.o, the link order in the above example is:
1. ./libbar.sl found
2. ./libme.sl not found
3. /var/tmp/libme.sl found
4. ./libc.sl not found
5. /usr/lib/pa20_64/libc.sl found
In the above example, if you type:
ld main.o -L. -lbar -lc
mv libme.sl /var/tmp
instead of:
mv libme.sl /var/tmp
ld main.o -L. -lbar -lc
the linker findslibme.sl in ./ at link time, and the dynamic loader
finds libme.sl 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. LD_LIBRARY_PATH to find libbar.sl not found
2. SHLIB_PATH to find libbar.sl not found