1、定义函数指针 typedef int (*my_func) (int,char*) my_func func_from_so; 2、加载so void *so_handle; char so_name[] = "xxx.so"; //dlopen : 推荐使用参数 RTLD_NOW ,表示立刻检查未定义变量的地址,如果解析不出来,在dlopen会返回NULL,dlerror返回非NULL(报错) so_handle = dlopen( so_name , RTLD_NOW ); char *error; if ((error = dlerror()) != NULL) { //错误处理 } 3、注册函数 //dlsym : 第二个参数为需要加载的so中的函数名 func_from_so = (my_func)dlsym(so_handle , "func"); if ((error = dlerror ()) != NULL) { dlclose( so_handle ); so_handle = NULL; //错误处理 } 4、卸载so dlclose( so_handle );