【发布时间】:2015-11-16 14:50:15
【问题描述】:
我是这个话题的新手。我正在尝试在我的 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
我正用头撞墙试图弄清楚这一点。有什么帮助吗?
【问题讨论】:
-
func的实现在哪里? -
你确定你知道你在做什么吗?请提供minimal reproducible example 并说明您想要完成的任务..
-
func 的实现因共享库不同而不同。我正在构建一个允许用户加载新插件的 shell
-
铸造通常以“另一种方式”完成:
func = (int (*)(char**)) dlsym(...);.
标签: c dll linker function-pointers