Nane
Nane

Reputation: 153

SWIG interface file for c++ header files

I have c++ a.h file like this

class myClass
{
private: 
  int a;
public: 
  myClass(){} 
  void foo(){}
};

How must look like SWIG interface file? Is this true?

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

Upvotes: 4

Views: 1626

Answers (1)

Mark Tolonen
Mark Tolonen

Reputation: 177901

No, %{ ... %} adds the included code directly to the generated SWIG wrapper. To process the header for interfaces to expose, %include needs to be used.

%module a
%{                // This adds the include to the generated wrapper.
#include "a.h"
%}
%include "a.h"    // This *processes* the include and makes wrappers.

If you have direct code not in a header needs to be added to the wrapper AND processed for interfaces, then %inline can be used to avoid duplication:

%module a
%inline %{
class myClass
{
private: 
  int a;
public: 
  myClass(){} 
  void foo(){}
};
%}

Upvotes: 5

Related Questions