HP-UX Linker and Libraries User's Guide
NOTE: You can use $ORIGIN in SHLIB_PATH/LD_LIBRARY_PATH only for programs on PA32
systems.
While the +origin option is available, the recommended way to specify $origin is in the
embedded path with the +b option. For example,
$ ld main.o -lc +b $ORIGIN
If you use +b,\$ORIGIN; the $ORIGIN only affects libraries that are subject to dynamic path
lookup; that is, the library shared_library_name is specified with -l or with no embedded /
character. If you use +origin shared_library_name, the library is located using $ORIGIN,
which is recorded in the full library name.
Changing the Default Shared Library Binding with -B
You might want to force immediate binding - that is, force all routines and data to be bound at
startup time. With immediate binding, the overhead of binding occurs only at program startup,
rather than across the program's execution. One useful characteristic of immediate binding is that
it causes any possible unresolved symbols to be detected at startup time, rather than during program
execution. Another use of immediate binding is to get better interactive performance, but in this
case the program startup may take a little longer.
$ ld -B immediate prog.o -lc
Example Using -B immediate
To force immediate binding, link an application with the -B immediate linker option. For example,
to force immediate binding of all symbols in the main program and in all shared libraries linked
with it, you can use this ld command:
$ ld -B immediate prog.o -lc
Nonfatal Shared Library Binding with -B nonfatal
The linker also supports nonfatal binding, which is useful with the -B immediate option. Like
immediate binding, nonfatal immediate binding causes all required symbols to be bound at program
startup. The main difference from immediate binding is that program execution continues even if
the dynamic loader cannot resolve symbols. Compare this with immediate binding, where unresolved
symbols cause the program to abort.
To use nonfatal binding, specify the -B nonfatal option along with the -B immediate option
on the linker command line. The order of the options is not important, nor is the placement of the
options on the line. For example, the following ld command uses nonfatal immediate binding:
$ ld prog.o -B nonfatal -B immediate -lc
Note that the -B nonfatal modifier does not work with deferred binding because a symbol
must be bound by the time a program actually references or calls it. A program attempting to call
or access a nonexistent symbol is a fatal error.
Restricted Shared Library Binding with -B restricted
The linker also supports restricted binding, which is useful with the -B deferred and -B
nonfatal options. The -B restricted option causes the dynamic loader to restrict the search
for symbols to those that were visible when the library was loaded. If the dynamic loader cannot
find a symbol within the restricted set, a run-time symbol-binding error occurs and the program
aborts.
The -B nonfatal modifier alters this behavior slightly: If the dynamic loader cannot find a
symbol in the restricted set, it looks in the global symbol set (the symbols defined in all libraries)
to resolve the symbol. If it still cannot find the symbol, then a run-time symbol-binding error occurs
and the program aborts.
32 Determining How to Link Programs or Libraries (Linker Tasks)