Example 1: Using the dynamic loading library in a C program.
void* library; /* The handle, pointing to the dynamic library */
void* get_foo; /* The function pointer, to point to get_foo() */
int foo; /* The return value from get_foo() */
/* Open the dynamic library libBar. The RTLD_NOW flag indicates that
* all of the symbols in the library should be loaded immediately
*/
library = dlopen("libBar.so", RTLD_NOW);
/* Load the get_foo symbol, which is a function of the form
* int get_foo(int x)
*/
get_foo = dlsym(library, "get_foo");
/* Call the get_foo() function */
foo = (*get_foo)(5);