我在C中创建了一个插件接口,它依赖于每个模块上的抽象基类和C-linkage工厂,如下所示:
plugin.h:
class Plugin
{
public:
virtual uint8_t some_number ( void ) = 0;
};
plugin1.cpp:
class plugin1
{
public:
uint8_t some_number ( void ) override;
};
extern "C" Plugin *
new_plugin
( void )
{
return new plugin1;
}
考虑到's no standard ABI, I'想要检查插件是否与应用程序兼容 . 为此,使用两个8位整数来标识接口版本 . 但是,这只能解决添加或删除方法的问题;它不处理应用程序和插件使用遵循不同约定的工具链构建的情况 .
是否有任何方法来编码ABI的标识符(即在编译时定义的以NULL结尾的字符数组)?像这样的东西:
/* defined by the compiler */
#define ABI "gnu-X.Y"
/* and then, in each plugin */
const char * plugin_abi = ABI;
因为我没有标准的方法来做到这一点,我将不得不从构建系统处理它 . Anyway, is there any method to encode the toolchain ABI for later retrieving and identifying through dlsym?
谢谢!