rvkreddy
rvkreddy

Reputation: 183

Interfacing C++ code with perl using SWIG

I have set of c++ classes which uses Boost and STL libraries and currently am making executable out of those classes in Linux.I want to create a perl interface to this c++ code using SWIG.

Say if i have 10 classes 1..10 and if i want to create an interface of class 1 with perl using SWIG and the main() function is in class 5

How should my interface file(*.i) should look like ? In what format should i build my C++ code ?

Upvotes: 1

Views: 249

Answers (1)

Alexander Solovets
Alexander Solovets

Reputation: 2507

You do not need to wrap main() to be able to create the interface for Class1. If want to have only that particular class in perl, then you should write

%module <your_module_name>

%{
#include "class1.h"
%}

%include "class1.h"

SWIG will scan class1.h and create corresponding wrappers for every class and function it will encounter. You can use %ignore to prevent certain symbols to be wrapped. If there are other types in the header of Class1, say Class2 and Class3, something like

class Class1 {
  Class2 foo();
  Class3 bar();
};

SWIG will issue an error because it doesn't know how to wrap those types. You either need to wrap them too, or if you do not want to expose other classes you can write

%import "class2.h"
%import "class3.h"

This will tell necessary type information to SWIG, but the wrappers will not be created.

Upvotes: 1

Related Questions