示例如下:
#include <stdio.h> #include <stdlib.h> #include <dlfcn.h> #include <signal.h> #include <errno.h> #define SO_FILE "test.so" typedef int (*FUN_CALL)(int, int); int main(const int argc, const char** argv) { void *pLib = NULL; FUN_CALL call = NULL; plib = dlopen(SO_FILE, RTLD_NOW | RTLD_GLOBAL); if ( NULL == plib ) { printf("%s\n", dlerror()); return -1; } call = dlsym(pLib , "call"); if ( NULL == call) { //ERROR return -1; } call(0, 1); //养成良好习惯 dlclose(pLib); }