Verifying Versions in Additional Objects
Version definition symbols also provide a
mechanism for verifying the version requirements of an
object obtained by
dlopen
(3C). An object that is added to
the process's address space by using
dlopen
(3C) receives no automatic
version dependency verification. Thus, the caller of
dlopen
(3C) is responsible for verifying
that any versioning requirements are met.
The presence of a required version definition
can be verified by looking up the associated version
definition symbol using
dlsym
(3C). The following example adds
the shared object libfoo.so.1
to a
process using
dlopen
(3C). The availability of the
interface SUNW_1.2
is then
verified.
#include <stdio.h> #include <dlfcn.h> main() { void *handle; const char *file = "libfoo.so.1"; const char *vers = "SUNW_1.2"; .... if ((handle = dlopen(file, (RTLD_LAZY | RTLD_FIRST))) == NULL) { (void) printf("dlopen: %s\n", dlerror()); return (1); } if (dlsym(handle, vers) == NULL) { (void) printf("fatal: %s: version '%s' not found\n", file, vers); return (1); } ....
Note:
The use of thedlopen
(3C) flag RTLD_FIRST
ensures that the
dlsym
(3C) search is restricted to libfoo.so.1
.