我正在为stepcode库(https://github.com/stepcode/stepcode)编写一个C# Package 器,使用SWIG(版本4.1.1)作为生成器。该库是高度模块化的,因此在某些情况下,一个 Package 器模块必须知道另一个模块的声明。
假设我在本机库中得到了以下结构:
- 模块1(clstepcore):此模块是提供类
Registry
和以下typedef的核心模块:
typedef void ( * CF_init )( Registry & ); // pointer to creation initialization
- 模块2(sdai_IFC4):该模块使用第一个模块的类型,因此SWIG提供了
%import
指令,以包含另一个模块描述文件,但不为该文件生成任何 Package 代码
(see:https://www.swig.org/Doc4.1/Preprocessor.html#Preprocessor_nn3)
代码如下所示:
clstepcore.i(为创建回调和注册表构造函数创建 Package 器)
%module clstepcore
%{
#include "Registry.h"
%}
class Registry;
typedef void ( * CF_init )( Registry & ); // pointer to creation initialization
class Registry {
public:
Registry( CF_init initFunct );
~Registry();
};
sdai_IFC4.i(为实际创建函数SchemaInit创建 Package )
%module sdai_IFC4
%{
#include "schema.h"
%}
%import "clstepcore.i"
%callback("%s_cb");
void SchemaInit (Registry &);
%nocallback;
不幸的是,为both模块生成的C#包含CF_init
typedef的精确定义,这导致了两个程序集之间的冲突。
我已经尝试过%ignore
之类的东西,但没有找到有效的解决方案。有没有人做过这样的东西,可以给我一个提示?先谢谢你了!
1条答案
按热度按时间yvt65v4c1#
不能在两个模块之间共享类型。这意味着所有模块都必须有自己的
Registry
副本,并且这些副本在模块之间不兼容。唯一的解决方案是在每个模块中重命名此类型: