69,369
社区成员
发帖
与我相关
我的任务
分享
int max(int a, int b)
{
return a > b ? a : b;
}
#include <dlfcn.h>
int main(void)
{
int max = 0;
int (*fun)(int, int);
void* handle = dlopen("libtest.so", RTLD_LAZY);
if (NULL == handle)
return -1;
fun = dlsym(handle, "max");
max = fun(3, 5);
dlclose(handle);
return 0;
}
#include <dlfcn.h>
typedef int (* pf_printf)(const char *format, ...);
int main(void)
{
void* handle = dlopen("libc.so.6", RTLD_LAZY);
if (! handle) return -1;
dlerror();
pf_printf mypf = (pf_printf)dlsym(handle, "printf");
if(0 != dlerror()) return -2;
mypf("this is a test\n");
dlclose(handle);
return 0;
}