(我使用动态加载API时存在一些问题<dlfcn.h>:dlopen(),dlclose()等),在Android上.我正在使用NDK独立工具链(版本8)来编译应用程序和库.Android版本是2.2.1 Froyo.
这是简单共享库的源代码.
#include <stdio.h>
int iii = 0;
int *ptr = NULL;
__attribute__((constructor))
static void init()
{
iii = 653;
}
__attribute__((destructor))
static void cleanup()
{
}
int aaa(int i)
{
printf("aaa %d\n", iii);
}
Run Code Online (Sandbox Code Playgroud)
这是使用上述库的程序源代码.
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
void *handle;
typedef int (*func)(int);
func bbb;
printf("start...\n");
handle = dlopen("/data/testt/test.so", RTLD_LAZY);
if (!handle)
{
return 0;
}
bbb = (func)dlsym(handle, "aaa");
if (bbb == NULL)
{
return …Run Code Online (Sandbox Code Playgroud)