HP-UX HB v13.00 Ch-11 - Software Development

HP-UX Handbook Rev 13.00 Page 98 (of 101)
Chapter 11 Software Development
October 29, 2013
Linker Related Variables
In fact, there is only one environment variable for the linker, LDOPTS. It has the same function as
the compiler variables, and it also works in the same way.
Runtime Related Variables
Of course, it is totally left to the programmer to determine which environment variables his
program reads, if any. But because every program uses dld.sl, at least the programs that are
linked shared, there are a few variables that allow us to tell the dynamic loader, how to load
shared libraries.
SHLIB_PATH can contain one or more colon separated directories that dld.sl will search first
when looking for shared libraries, before looking in the default locations stored in the executable.
To put SHLIB_PATH in effect for an executable, it must have “library search” via this +s variable
enabled. This setting is determined by a flag in the executable that can either be set at link time
by using the +s linker option, or it can be viewed and changed with chatr(1).
LD_LIBRARY_PATH has the same purpose, effect and usage as SHLIB_PATH, but it only works for
ELF programs (IA64 and 64-bit PA-RISC). This variable was introduced for compatibility
reasons to other Unix derivates (e.g. SunOS, Linux).
LD_PRELOAD can contain one or more colon separated shared library file names which will be
loaded first, before any of the shared libraries listed in the executable's shared library list are
loaded. The effect is that symbol resolution at runtime will change. Every symbol will first be
searched in the libraries listed in LD_PRELOAD, before it is searched in the libraries linked to the
executable. Be very careful when using this variable because it can change the behaviour of
a program significantly. When using LD_PRELOAD you should never do:
$ export LD_PRELOAD=<library>
$ <program>
because every subsequently executed program and command would use the library specified in
<library>, which could lead to undesired results. To make a certain program use an additional
library, it is better to start it with:
$ LD_PRELOAD=<library> <program>
Or
$ LD_PRELOAD=<library>
$ program
$ unset LD_PRELOAD
Then LD_PRELOAD is only exported for <program>.