C++ 头文件的 SWIG 接口文件

Nan*_*ane 4 swig

我有这样的 c++ ah 文件

class myClass
{
private: 
  int a;
public: 
  myClass(){} 
  void foo(){}
};
Run Code Online (Sandbox Code Playgroud)

SWIG 接口文件必须是什么样子?这是真的?

%module a
%{
#include "a.h"
%}
Run Code Online (Sandbox Code Playgroud)

Mar*_*nen 5

否,%{ ... %}将包含的代码直接添加到生成的 SWIG 包装器中。要处理要公开的接口的标头,%include需要使用。

%module a
%{                // This adds the include to the generated wrapper.
#include "a.h"
%}
%include "a.h"    // This *processes* the include and makes wrappers.
Run Code Online (Sandbox Code Playgroud)

如果您有不在标头中的直接代码需要添加到包装器并针对接口进行处理,则%inline可以使用以避免重复:

%module a
%inline %{
class myClass
{
private: 
  int a;
public: 
  myClass(){} 
  void foo(){}
};
%}
Run Code Online (Sandbox Code Playgroud)