I can not reproduce the basic SWIG example on windows. My mistake is indicated in the SWIG docs, and I am sure that I am making 2 corrections that they mention. For this error:
>>> import example
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "example.py", line 2, in ?
import _example
ImportError: No module named _example
The SWIG documentation clearly states:
forget about the underscore (_).
forget about the underscore (_). > If you receive this message, it means that
you either forgot to compile the shell code into an extension module or you did not give the extension enter the correct name. Make sure you compile the wrappers in a module called example.so. And don't forget the front underscore (). forget the main underscore (_).
, , : "_example", "_example.so", "example.dll", "example.so", "example.dll", "example.py" , , python , ().
:
int foo_sum(int a, int b);
.
int foo_sum(int a, int b) {
return a + b;
}
.
//example.i
%module example
%{
#include "example.h"
%}
#include "example.h
:
gcc -IV:\temp\example\external\include\Python -O3 -Wall -c -fmessage-length=0 -oexample_wrap.o ..\example_wrap.c
g++ -IV:\temp\example\external\include\Python -O3 -Wall -c -fmessage-length=0 -oexample.o ..\example.cpp
g++ -LV:\temp\example\external\lib -shared -oexample.dll example_wrap.o example.o -lpython26
-O3, ( Release)
:
>>> import sys
>>> sys.path.append("/your/module/path")
>>> import example
EDIT:
, dll, "_example.pyd", "foo_sum"
EDIT:
, extern "C" .i