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>
<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?
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.