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;
}
}
本文详细解析了如何在Android C层通过使用C标准库和动态链接库(dlopen, dlsym)加载.so库文件,并提供了加载过程中的错误处理和功能调用的完整代码示例。
1054

被折叠的 条评论
为什么被折叠?



