Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWIG interface file for c++ header files

Tags:

swig

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"
%}
like image 477
Nane Avatar asked Oct 14 '25 14:10

Nane


1 Answers

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(){}
};
%}
like image 166
Mark Tolonen Avatar answered Oct 18 '25 22:10

Mark Tolonen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!