I am having some trouble generating a Python wrapper around a C++ library using SWIG (version 3.0.6).
My issue relates to applying the OUTPUT typemap, specifically i
I think you need to use pointers. I am also not sure what happens, when mixing out typemaps and return statements. A minimal example file tst.i:
%module tst
%{
// declaration:
void add(long *resultLong, const long arg1,const long arg2);
long mul(const long a, const long b);
// the code:
void add(long *resultLong, const long arg1,const long arg2) {
*resultLong = arg1 + arg2;
}
long mul(const long a, const long b) {
return a*b;
}
%}
// The wrapper:
%apply (long* OUTPUT) { long* resultLong };
void add(long* resultLong, const long arg1,const long arg2);
long mul(const long a, const long b);
After translating (I always use CMake), the usage in python would be:
import tst
x = tst.add(3, 4) # results in 7L
y = tst.mul(3, 4) # results in 12L
I think it is better using return statements instead of typemaps for scalar datatypes. When interfacing arrays, I recommend using the predefined typemaps of numpy.i.