DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

dlsym(S-osr5)


dlsym -- get the address of a symbol in a dynamically linked library

Syntax

cc . . . -lc

#include <dlfcn.h>

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

Description

dlsym(S-osr5) allows a process to obtain the address of a symbol defined within a shared object (dynamically linked library) previously opened by dlopen(S-osr5). handle is a value returned by a call to dlopen( ); the corresponding shared object must not have been closed using dlclose(S-osr5). name is the symbol's name as a character string. dlsym( ) searches for the named symbol in all shared objects loaded automatically as a result of loading the object referenced by handle. See dlopen(S-osr5).

Return values

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(S-osr5).

Examples

The following example shows how dlopen( ) and dlsym( ) can be used 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");

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

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

i = (*fptr)(*iptr);

See also

dlclose(S-osr5), dlerror(S-osr5), dlopen(S-osr5)

Standards conformance

dlsym(S-osr5) is not part of any currently supported standard; it is an extension of AT&T System V provided by The Santa Cruz Operation, Inc.


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005