Android C层如何加载.so库文件:
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <errno.h>
int (*jmain)(int arg1, char* arg2) = NULL;
void int callSoJMainFunction(int arg1, char* arg2) {
void* handle = dlopen(szSoPath, RTLD_LAZY);
if (handle == NULL) {
printf(“dlopen file error:%s %s\n", szSoPath, strerror(errno));
return -1;
} else {
printf("dlopen file OK: %d\n", handle);
}
jmain = dlsym(handle, "main");
if(jmain == NULL) {
printf("get main function error\n");
dlclose(handle);
return -1;
} else {
printf("dlsym OK: 0x%08X\n", jmain);
int result = jmain(arg1, arg2);
dlclose(handle);
return result;
}
}