- 源码
#include
#include
#include
#include
#include
#define SO_FILE "test.so"
#define FUNC_NAME "call"
typedef int (*FUN_CALL)(int, int);
int main(const int argc, const char** argv)
{
void *pLib = NULL;
FUN_CALL pCall = NULL;
pLib = dlopen(SO_FILE, RTLD_NOW | RTLD_GLOBAL);
if ( NULL == pLib )
{
printf("%s\n", dlerror());
return -1;
}
pCall = (FUN_CALL)dlsym(pLib , FUNC_NAME);
if ( NULL == pCall )
{
//ERROR
return -1;
}
pCall(0, 1);
//养成良好习惯
dlclose(pLib);
}
- 编译
gcc test.c -o test -ldl