Augmenting the Default Linker Search Path with
The
For example, suppose you have a locally developed version of libc, which resides in the directory /usr/local/lib. To make ld find this version of libc before the default libc, use the
$ ld prog.o
If LPATH is set, then the
Augmenting the Default Linker Search Path with +origin
The +origin option to ld instructs the linker to search for the library in the directory from which the object module originated.
The +origin option only applies to the shared library specified directly afterwards, for example, libc.so or
At runtime, if the dynamic loader cannot find the library listed in the path specified by $ORIGIN, it attempts to search paths according to the search path algorithm described above.
The syntax is as follows:
$ ld main.o +origin
or
$ ld main.o +origin /usr/lib/hpux32/libc.so
Using $ORIGIN
You can use the $ORIGIN string in LD_LIBRARY_PATH, SHLIB_PATH, RUNPATH (the embedded path or RPATH), or in the path of a shared library in the shared library list. If the DF_ORIGIN flag is set, the loader determines the path of the current load module when the load module is first loaded. If the DF_ORIGIN flag is not set, the loader determines the path of the current load module when the loader first encounters $ORIGIN, whether it is in LD_LIBRARY_PATH, SHLIB_PATH, RUNPATH, or the shared library name in the shared library list.
To add $ORIGIN to the environment variables LD_LIBRARY_PATH or SHLIB_PATH, place
$ORIGIN in the value of these environment variables. To add $ORIGIN to the RUNPATH, use the linker options +b or
+origin
or
+origin shared_library_name
(You can use only the +origin option before the
$ ld main.o +origin libx.so
Using Linker Commands 31