Linker and Libraries Guide

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 to a process using dlopen(3C). The availability of the interface SUNW_1.2 is then verified.

#include        <stdio.h>
#include        <dlfcn.h>
        void       *handle;
        const char *file = "";
        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 the dlopen(3C) flag RTLD_FIRST ensures that the dlsym(3C) search is restricted to