Using swig to package a large library

I have a fairly complex, C ++ templating library, with hundreds of classes and many thousands of lines of code. the only external dependence is on the rise. I would like to access this library from R, python, etc.

from what I've read, it seems like walking is the way to go. but the tutorial seems to work with one binary by writing the appropriate .i file. now writing an .i file for each class and file into the library at hand will probably take weeks, if not a month. this is not an option at the moment.

so my question is:

  • Is there any practical tutorial for "swigging" a large Pre-library?

  • Can swig generate these .i files more or less automatically?

  • If not, is there an alternative?

+3


source to share


1 answer


I haven't seen any great tutorials, but the SWIG documentation is decent.

SWIG does not generate .i files, but it has many useful pre-encoded .i files. For example, windows.i

for Windows type support, std_vector.i

for std :: vector C ++ support, etc.

SWIG handles .h files, so you don't have to write wrappers by hand for all of your classes. A simple .i file as shown below will do most of the work for you.



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

%include <windows.i> // If on windows...
%include "mylib.h"

      

If your classes and methods have standard parameter types and return values, they can "just work". However, more complex types may require additional includes, template instances, or handwritten types.

Other alternatives for wrapping C ++ libraries are boost::Python

, but I haven't played with it myself.

0


source







All Articles