From the book Advanced Linux Programming:
--open quote--
2.3.6 Dynamic Loading and Unloading
Sometimes you might want to load some code at run time without
explicitly linking in that code. For example, consider an application
that supports "plug-ins" modules, such as a Web browser...
This Functionality is avaliable under Linux by using the dlopen()
function. You could open a shared library named libtest.so by calling
dlopen() like this:
dlopne("libtest.so", RTLD_LAZY)
(The second parameter is a flag that indicates how to bind symbols in
the shared library. You can consult the man pages for dlopen if you
want more information, but RTLD_LAZY is usually the setting that you
want.) Yo use dynamic loading functions, include the <dlfcn.h> header
file and link with the -ldl option to pick up the libdl library.
The return value from this function is a void * that is used as a
handle for the shared library. You can pass this value to the dlsym()
function to obtain the address of a function that has been loaded with
the shared library. For example, if libtest.so defines a function
named my_function(), you could call it like this:
void* handle = dlopen("libtest.so", RTLD_LAZY);
void (*test)() = dlsym(handle, "my_function");
(*test)();
dlclose(handle);
The dlsym() system call can also be used to obtain a pointer to a
static variable in the shared library.
Both dlopen() and dlsym() return NULL if they do not succeed. In that
event you can call dlerror() (with no parameters) to obtain a
human-readable error message describing the problem.
The dlclose() function unloads the shared library. Technically,
dlopen() actually loads the library only if it is not already
loaded. If the library has already been loaded, dlopen() simply
increments the library reference count. Similarly, dlclose()
decrements the reference count and then unloads the library only if
the reference count has reached zero.
--close quote--
Maybe that might help.
Regards
--
Gustavo G. Rondina
http://gustgr.freeshell.org