解析共享库的

时间:2015-05-26 19:11:48

标签: c shared-libraries

在C程序中,我想使用dlopen将特定模块添加为共享库。

dlopenRTLD_LAZY一起使用(使用RTLD_NOW直接失败可能是由于以下原因)和dlsym我可以创建我想要的实际函数的句柄呼叫。调用函数后,我收到错误

program: symbol lookup error: file.so: undefined symbol: createExpressionNumber

函数createExpressionNumber是程序的一个功能。共享库由

编译
gcc -fPIC -c ...

并通过

链接
gcc -shared ...

看来,当链接为共享库时这些符号没有被解析(这是有道理的)但是打开lib时我的程序不提供这些符号。

有没有办法将我的程序的功能提供给加载的共享库,还是我需要从我的程序中提取共享库使用的所有函数作为单独的共享库?

1 个答案:

答案 0 :(得分:1)

您的主程序链接行需要-rdynamic。那会:

Pass the flag -export-dynamic to the ELF linker, on targets that support it. This instructs the linker to add all symbols, not only used ones, to the dynamic symbol table. This option is needed for some uses of "dlopen" or to allow obtaining backtraces from within a program.

即。允许动态加载的共享库来查找主可执行文件的符号。

相关问题