无法包装标题文件中定义的简单类

Cannot wrap simple class defined in header file

本文关键字:定义 简单 文件 包装 标题      更新时间:2023-10-16

我被卡在用csharp包装.so文件的开始阶段。但是,如果我尝试使用包含类的提供的H文件之一创建包装器,那么我会遇到错误。我认为这是因为__attribute__ ((visibility ("default") )),但我无法弄清楚。有没有人做过这个?

我在测试中定义了一个类别。H如下:

class Test
{
  public:
    __attribute__ ((visibility ("default") )) Test();
    __attribute__ ((visibility ("default") )) ~Test();
};

我定义了一个接口文件,正如您想象的那样,该文件也很简单。

%module Test
%{
#include "Test.h"
%}

/* Let's just grab the original header file here */
%include "Test.h"

执行命令swig -c++ -csharp -v test.i时,我会收到错误消息:

Test.h:4: Error: Syntax error in input(3).

swig对__attribute__一无所知。您需要用它包装:

%module Test
%{
#include "Test.h"
%}
#define __attribute__(x) 
/* Let's just grab the original header file here */
%include "Test.h"