220 Chapter 6
Shared Library Management Routines
The shl_load Shared Library Management Routines
}
/*
* Dynamically load the shared library using BIND_IMMEDIATE
binding:
*/
lib_handle = shl_load( lib_path, BIND_IMMEDIATE, 0);
if (lib_handle == NULL)
perror(“shl_load: error loading library”), exit(1);
return lib_handle;
}
BIND_NONFATAL Modifier
If you load a shared library with the BIND_IMMEDIATE flag and the
library contains unresolved symbols, the load fails and sets errno to
ENOSYM. ORing BIND_NONFATAL with BIND_IMMEDIATE causes
shl_load to allow the binding of unresolved symbols to be deferred if
their later use can be detected — for example:
shl_t libH;
...
libH = shl_load("libxyz.sl", BIND_IMMEDIATE | BIND_NONFATAL, 0);
However, data symbol binding cannot be deferred, so using the
BIND_NONFATAL modifier does not allow the binding of unresolved data
symbols.
BIND_VERBOSE Modifier
If BIND_VERBOSE is ORed with the flags parameter, the dynamic loader
displays messages for all unresolved symbols. This option is useful to see
exactly which symbols cannot be bound. Typically, you would use this
with BIND_IMMEDIATE to debug unresolved symbols — for example:
shl_t libH;
...
libH = shl_load("libxyz.sl", BIND_IMMEDIATE | BIND_VERBOSE, 0);
BIND_FIRST Modifier
If BIND_FIRST is ORed with the flags parameter, the loaded library is
inserted before all other loaded shared libraries in the symbol resolution
search order. This has the same effect as placing the library first in the
link order — that is, the library is searched before other libraries when
resolving symbols. This is used with either BIND_IMMEDIATE or
BIND_DEFERRED — for example:
shl_t libH;
...
libH = shl_load("libpdq.sl", BIND_DEFERRED | BIND_FIRST, 0);