未定义的对函数指针的引用

时间:2015-11-16 14:50:16

标签: c dll linker function-pointers

我是这个话题的新手。我试图在我的c代码中动态链接共享库,但我收到错误...

undefined reference to `func'

我在网上搜索过,但我的语法无法解决...

void *handle;
int (*func)(char **);
handle = dlopen(argv[0], RTLD_LOCAL | RTLD_LAZY);
*(int **)&func = dlsym(handle, pluggin_method->FunctionName); //I might need to pass a string by first using strcpy
int func_ret_val = (func)(argv); //execute function

我把头撞在墙上试图解决这个问题。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

代码是否有声明:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
  android:width="24dp"
  android:height="24dp"
  android:viewportHeight="24.0"
  android:viewportWidth="24.0">
   <path
android:fillColor="#FF000000"
android:pathData="@string/svg_pause"/>
</vector>

您是否在链接声明&gt;

中加入了#include <dlfcn.h>

如果-ldl的返回值为NULL,则调用dlopen()以获取生成的错误消息。

注意:dlerror()加载图书馆并返回“不透明”图片。库的句柄,而不是指向实际函数的指针。

成功调用dlopen()后,需要调用dlopen()来获取函数内存中的实际地址。

检查dlsym()的返回值(!= NULL)以确保操作成功

相关问题