DLVSYM(3)

NAME
dlvsym - shared object symbol lookup by version function

LIBRARY
This function is not in a library. It is included in every dynamically linked program automatically.

SYNOPSIS
#include <dlfcn.h>
void *
dlvsym(void * restrict handle, const char * restrict name, const char * restrict version);

DESCRIPTION
The dlvsym() function does the same as dlsym(3) but takes a version string as an additional argument. Both the name and the version must match in order for the symbol to be resolved.

NOTES
ELF executables need to be linked using the -export-dynamic option to ld(1) for symbols defined in the executable to become visible to dlvsym().

RETURN VALUES
The dlvsym() function returns the address of the symbol unless the symbol can not be found. In this case, it returns a null pointer and sets an error condition which may be queried with dlerror().

EXAMPLES
The following program will obtain a pointer to the gcc library __adsvsi3 function using dlvsym specified to version GCC_3.0, and then it will use it to print out the sum of 500 + 325.

    #include <dlfcn.h>
    #include <stdlib.h>
    #include <stdio.h>
    int
    main (int argc, char *argv[])
    {
        void       *handle;
        int        (*func_sum)(int a, int b);
        /* open the dports shared gcc410 library  */
        handle = dlopen("/usr/local/lib/gcc410/libgcc_s.so", RTLD_LAZY);
        if (!handle) {
           fprintf (stderr, "%s\n", dlerror ());
           exit (EXIT_FAILURE);
        }
        /* get pointer to integer sum function */
        func_sum = dlvsym (handle, "__addvsi3", "GCC_3.0");
        if (func_sum == NULL) {
           fprintf (stderr, "function %s version %s not found\n",
                    "__addvsi3", "GCC_3.0");
           dlclose (handle);
           exit (EXIT_FAILURE);
        }
        /* Calculate and display the sum of 500 + 325 */
        printf ("500 + 325 = %d\n", func_sum((int)500, (int)325));
        dlclose (handle);
        exit(EXIT_SUCCESS);
    }

SEE ALSO
rtld(1), dlfcn(3), dlsym(3)

HISTORY
The dlvsym function first appeared in DragonFly 2.11.