*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->IRIX man pages -> libdl/dlsym (3)              
Title
Content
Arch
Section
 

Contents


DLSYM(3C)							     DLSYM(3C)


NAME    [Toc]    [Back]

     dlsym - get the address of	a symbol in shared object

SYNOPSIS    [Toc]    [Back]

     cc	[flag ...] file	...  -lc [library ...]

     #include <dlfcn.h>

     void *dlsym(void *handle, const char *name);

DESCRIPTION    [Toc]    [Back]

     dlsym allows a process to obtain the address of a symbol defined within a
     shared object previously opened by	dlopen,	sgidlopen_version, or
     sgidladd.	handle is a value returned by a	call to	dlopen;	the
     corresponding shared object must not have been closed using dlclose.
     name is the symbol's name as a character string.  dlsym searchs for the
     named symbol in all shared	objects	loaded automatically as	a result of
     loading the object	referenced by handle [see dlopen(3)].

     The name search is	done in	the following order:
	 If the	handle is NULL,	the base object	is searched and	then the rldlist
 of objects is searched, looking only at globally-visible DSOs.

	 If the	handle is not NULL, the	named object is	searched and then the
	 library list of the DSO opened	on handle is searched (in a pre-order
	 breadth-first search of all listed DSOs).

	 The first visible symbol with the requested name (weak	or strong) is
	 returned.

     For information on	how names are generally	resolved (as distinct from
     dlsym resolution) and on symbol visibility	see the	dlopen "NAMESPACE
     ISSUES" section.

     Note that name resolution for names on the	NULL handle is in rld-list
     order whereas for other handles the resolution is in library-list order.

EXAMPLES    [Toc]    [Back]

     The following example shows how one can use dlopen	and dlsym to access
     either function or	data objects.  For simplicity, error checking has been
     omitted.

	  void *handle;
	  int i, *iptr;
	  int (*fptr)(int);

	  /* open the needed object */
	  handle = dlopen("/usr/mydir/libx.so",	RTLD_LAZY);

	  /* find address of function and data objects */
	  fptr = (int (*)(int))dlsym(handle, "some_function");




									Page 1






DLSYM(3C)							     DLSYM(3C)



	  iptr = (int *)dlsym(handle, "int_object");

	  /* invoke function, passing value of integer as a parameter */

	  i = (*fptr)(*iptr);

SEE ALSO    [Toc]    [Back]

      
      
     dlerror(3), dlopen(3), sgidlopen_version(3), dlclose(3),
     sgigetdsoversion(3), sgidladd(3).

DIAGNOSTICS    [Toc]    [Back]

     The C or C++ compiler may emit a warning similar to "warning(1048): cast
     between pointer-to-object and pointer-to-function"	when casting the
     return type of dlsym to be	a function pointer.  While a cast from
     pointer-to-data to	pointer-to-function is not necessarily portable	to all
     systems (which is what the	warning	means) the cast	and the	resulting call
     will work fine on any system actually supporting dlsym.  One could	define
     a function
     int (*dlsymfunc(void *handle,char *name))();
     int (*dlsymfunc(void *handle,char *name))()
     {
	     return (int (*)())dlsym(handle,name);
     }
     and call it instead of dlsym when getting function	addresses: that	has
     the effect	of moving the warning message to a single spot in the program
     (the dlsymfunc definition)	so the rest of the code	does not get this
     warning.

     If	handle does not	refer to a valid object	opened by dlopen, or if	the
     named symbol cannot be found within any of	the objects associated with
     handle, dlsym returns NULL. More detailed diagnostic information is
     available through dlerror.


									PPPPaaaaggggeeee 2222
[ Back ]
 Similar pages
Name OS Title
dlsym Tru64 obtain the address of a symbol from a dlopen() object
dladdr FreeBSD find the shared object containing a given address
st_data_addr_to_sym Tru64 convert an address in an object to a file handle, procedure handle, line number, or symbol handle an...
st_addr_to_file Tru64 convert an address in an object to a file handle, procedure handle, line number, or symbol handle an...
st_addr_to_sym Tru64 convert an address in an object to a file handle, procedure handle, line number, or symbol handle an...
st_addr_to_line Tru64 convert an address in an object to a file handle, procedure handle, line number, or symbol handle an...
st_addr_to_proc Tru64 convert an address in an object to a file handle, procedure handle, line number, or symbol handle an...
st_text_addr_to_sym Tru64 convert an address in an object to a file handle, procedure handle, line number, or symbol handle an...
ldgetname IRIX retrieve symbol name for object file symbol table entry
ldgetname Tru64 retrieve symbol name for object file symbol table entry
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service