1

I am fairly new to SWIG (and c++), so I was trying to use an example from this website It seems like a simple code. I compiled it...successfully (I think?) on Visual Studio.

1>------ Rebuild All started: Project: minimal, Configuration: Release x64 ------
1>Performing Custom Build Tools
1>minimal.cpp
1>minimal_wrap.cxx
1>   Creating library ..._minimal2.lib and object ...minimal2.exp
1>Generating code
1>Previous IPDB not found, fall back to full compilation.
1>All 70 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
1>Finished generating code
1>minimal.vcxproj -> C:\...\_minimal.pyd
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

But then when I tried to run it on spyder (ipython console)

import _minimal
m1 = minimal.minimal()
print(m1)

outputs <minimal.minimal; proxy of <Swig Object of type 'minimal2 *' at 0x000001D0C68BDDE0>

From the tutorial website, it sounds like I should get some integers?

m1.print_num_instances()

This command results in no output... is my file not built correctly?

kwangsk
  • 36
  • 4

1 Answers1

0

So it looks like I had to add "typemaps.i" and define output type. I did not work on the example used in my question above but I found another example very helpful.

/* typemaps.i allows input and output pointer arguments to be specified using the names INPUT, OUTPUT, or INOUT */
%include "typemaps.i"

void   hw1(double r1, double r2, double *OUTPUT);

The example shows their first attempt failing with a similar pointer kind of response I got. Then after typeamps.i, it hw1 function works!

kwangsk
  • 36
  • 4
  • So if you read the swig documentaiton, typemaps is generally not needed... I think in this case (hw1) it was needed because of the way the void function was constructed. I just tested another simple c file with int function and it works well without typemaps (just had to put extern int or extern double). – kwangsk Apr 29 '20 at 16:43