Dynamically loading a function within a .so

Dynamically loading a function within a .so

Post by David Su » Fri, 11 Feb 2000 04:00:00



How can I dynamically load a particular function from a shared object?  At run
time I want the program to determine which shared object it wants to load and
then get a function pointer to a particular function within that shared object.  
The list of potential shared objects is not known at compile time so I cannot
include them in the build process at all.

Thanks,
David Suna

 
 
 

Dynamically loading a function within a .so

Post by mon.. » Fri, 11 Feb 2000 04:00:00



>How can I dynamically load a particular function from a shared object?  At
>run time I want the program to determine which shared object it wants to
>load and then get a function pointer to a particular function within that
>shared object.

I believe the functions dlopen, dlsym, and dlclose do this.  'man dlopen'
should explain how to use them.  I haven't used them before, but it also
looks like you have to link to the dl library with -ldl to make them work.
The header file these functions require is dlfcn.h.

Good luck. :)