动态加载so
static void *glib_handle = NULL;
typedef int (*_open_node)(void);
typedef void (*_close_node)(void);
_open_node open_node = NULL;
_close_node close_node = NULL;
bool load(void)
{
const char *errstr;
#if defined(__LP64__) && __LP64__
LOGD(TAG"%s __LP64__defined and __LP64__\n", __FUNCTION__);
glib_handle = dlopen("/system/lib64/test.so", RTLD_LAZY);
#else
glib_handle = dlopen("/system/lib/test.so", RTLD_LAZY);
#endif
if (!glib_handle){
ERR("%s\n", dlerror());
goto load_error;
}
dlerror(); /* Clear any existing error */
open_node = dlsym(glib_handle, "open_node");
close_node = dlsym(glib_handle, "close_node");
if ((errstr = dlerror()) != NULL){
ERR("Can't find function symbols %s\n", errstr);
goto load_error;
}
return true;
load_error:
if (glib_handle){
dlclose(glib_handle);
glib_handle = NULL;
}
return false;
}