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

时间:2017-12-12 18:37:01

标签: c++ swig

我陷入了使用csharp包装.so文件的开始阶段。但是,如果我尝试使用提供的包含类的h文件之一创建包装器,那么我会收到错误。我认为这是因为__attribute__ ((visibility ("default") )),但我无法弄明白。有没有人曾经这样做过?

我在Test.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).

1 个答案:

答案 0 :(得分:1)

SWIG对__attribute__一无所知。你需要用它包装它:

%module Test

%{
#include "Test.h"
%}

#define __attribute__(x) 

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