说我有一个父母和一个孩子,孩子用dlopen在孩子中调用一个函数“hello”。然后孩子可以在父母中调用“世界”功能吗?我不断收到符号查找错误:./ child.so:undefined symbol:world
这是文件。 parent.c
#include <dlfcn.h>
typedef void (*fptr)();
#include <stdio.h>
int main () {
void*handle=dlopen("./child.so",RTLD_LAZY);
fptr f=dlsym(handle,"hello");
f();
return 0;
}
void world() {
printf ("world");
}
和child.c
#include <stdio.h>
void hello () {
printf ("hello");
world();
}
答案 0 :(得分:1)
是的,dlopen
- ed模块可以调用来自调用程序的函数,前提是调用程序已与-rdynamic
选项链接。
另请阅读visibility函数__attribute__
...另请阅读Drepper's How to Write Shared Libraries长篇论文和dlopen(3)手册页。
答案 1 :(得分:1)
我在谷歌找到了答案
http://www.justskins.com/forums/dlopen-calling-functions-other-104185.html
gcc -rdynamic hello.c -ldl
答案 2 :(得分:0)
令人惊讶的是它可以。我亲眼看到它发生了。
您可能需要使用-rdynamic