学习“用dlopen,dlsym加载动态链接库.so中函数”之摘录

参考链接:https://www.cnblogs.com/eniac1946/p/7462082.html

直接上代码:

static void *findSymbol(const char *path, const char *symbol) 
{
  void *handle = dlopen(path, RTLD_LAZY);
  if (!handle) {
    LOGE("handle %s is NULL", path);
    return NULL;
  }

  void *target = dlsym(handle, symbol);
  if (!target) {
    LOGE("symbol %s is NULL", symbol);
  }
  return target;
}

void *target = findSymbol("libc.so", "__system_property_get");

dlopen打开失败,可以用dlerror()查看错误,看代码:

void *dlh;
dlh = dlopen("libdes3-32.so", RTLD_NOW | RTLD_GLOBAL);
if (dlh == NULL) {
  printf("dlopen err:%s.\n", dlerror());
}


猜你喜欢

转载自blog.csdn.net/zhangge3663/article/details/80323356
今日推荐