1.\" This source code is a product of Sun Microsystems, Inc. and is provided 2.\" for unrestricted use provided that this legend is included on all tape 3.\" media and as a part of the software program in whole or part. Users 4.\" may copy or modify this source code without charge, but are not authorized 5.\" to license or distribute it to anyone else except as part of a product or 6.\" program developed by the user. 7.\" 8.\" THIS PROGRAM CONTAINS SOURCE CODE COPYRIGHTED BY SUN MICROSYSTEMS, INC. 9.\" SUN MICROSYSTEMS, INC., MAKES NO REPRESENTATIONS ABOUT THE SUITABLITY 10.\" OF SUCH SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT 11.\" EXPRESS OR IMPLIED WARRANTY OF ANY KIND. SUN MICROSYSTEMS, INC. DISCLAIMS 12.\" ALL WARRANTIES WITH REGARD TO SUCH SOURCE CODE, INCLUDING ALL IMPLIED 13.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN 14.\" NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT, 15.\" INCIDENTAL, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 16.\" FROM USE OF SUCH SOURCE CODE, REGARDLESS OF THE THEORY OF LIABILITY. 17.\" 18.\" This source code is provided with no support and without any obligation on 19.\" the part of Sun Microsystems, Inc. to assist in its use, correction, 20.\" modification or enhancement. 21.\" 22.\" SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 23.\" INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS 24.\" SOURCE CODE OR ANY PART THEREOF. 25.\" 26.\" Sun Microsystems, Inc. 27.\" 2550 Garcia Avenue 28.\" Mountain View, California 94043 29.\" 30.\" Copyright (c) 1991 Sun Microsystems, Inc. 31.\" 32.\" $FreeBSD: src/lib/libc/gen/dlopen.3 211397 2010-08-16 15:18:30Z joel $ 33.\" 34.Dd October 10, 2014 35.Dt DLVSYM 3 36.Os 37.Sh NAME 38.Nm dlvsym 39.Nd shared object symbol lookup by version function 40.Sh LIBRARY 41This function is not in a library. 42It is included in every dynamically linked program automatically. 43.Sh SYNOPSIS 44.In dlfcn.h 45.Ft "void *" 46.Fn dlvsym "void *handle" "const char *name" "const char *version" 47.Sh DESCRIPTION 48The 49.Fn dlvsym 50function 51does the same as 52.Xr dlsym 3 53but takes a version string as an additional argument. Both the name and 54the version must match in order for the symbol to be resolved. 55.Sh NOTES 56ELF executables need to be linked 57using the 58.Fl export-dynamic 59option to 60.Xr ld 1 61for symbols defined in the executable to become visible to 62.Fn dlvsym . 63.Sh RETURN VALUE 64The 65.Fn dlvsym 66function 67returns the address of the symbol unless the symbol can not be found. 68In this case, it returns a null pointer and sets an error condition 69which may be queried with 70.Fn dlerror . 71.Sh EXAMPLE 72The following program will obtain a pointer to the gcc library __adsvsi3 73function using dlvsym specified to version GCC_3.0, and then it will use it 74to print out the sum of 500 + 325. 75.Bd -literal 76#include <dlfcn.h> 77#include <stdlib.h> 78#include <stdio.h> 79 80int 81main (int argc, char *argv[]) 82{ 83 void *handle; 84 int (*func_sum)(int a, int b); 85 86 /* open the dports shared gcc410 library */ 87 handle = dlopen("/usr/local/lib/gcc410/libgcc_s.so", RTLD_LAZY); 88 if (!handle) { 89 fprintf (stderr, "%s\en", dlerror ()); 90 exit (EXIT_FAILURE); 91 } 92 93 /* get pointer to integer sum function */ 94 func_sum = dlvsym (handle, "__addvsi3", "GCC_3.0"); 95 if (func_sum == NULL) { 96 fprintf (stderr, "function %s version %s not found\en", 97 "__addvsi3", "GCC_3.0"); 98 dlclose (handle); 99 exit (EXIT_FAILURE); 100 } 101 102 /* Calculate and display the sum of 500 + 325 */ 103 printf ("500 + 325 = %d\en", func_sum((int)500, (int)325)); 104 dlclose (handle); 105 106 exit(EXIT_SUCCESS); 107} 108.Ed 109.Sh SEE ALSO 110.Xr rtld 1 , 111.Xr dlfcn 3 , 112.Xr dlsym 3 113.Sh HISTORY 114The 115.Nm 116function first appeared in 117.Dx 2.11 . 118