我目前正在尝试使用 Qt 的 QPluginLoader 构建一个插件系统。在我将编译为 DLL (.so) 的插件中,我需要使用一些编译到主二进制文件中的类(这将加载插件)。
这不起作用,因为在运行时通过 QPluginLoader 加载将失败并显示错误消息:Cannot load library ... plugin.so.1.0.0: undefined symbol 。 ..
所以这些符号实际上在我的主二进制文件中,我想在我的 DLL 中使用它们...但是为什么这些符号对 DLL 不可用?有可能以某种方式实现这一目标吗? (希望有一些神奇的编译标志......)
注意:我可以将主程序的源代码编译到我的 DLL 中,但这在构建插件系统时听起来很愚蠢!
最佳答案
编译标志-export-dynamic 将解决这个问题。以下是 gcc 文档中的描述:
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.
关于c++ - 使用加载二进制文件中的 DLL 中的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26984582/