Advertisement

SWIG problem with python

Started by August 05, 2004 02:17 PM
0 comments, last by Aldacron 20 years, 3 months ago
I've made a couple of c functions in a dll build with vc++ 6.0. I've used swig to expose it to python. Now, when I try to import the module in python I get the error message: >>> import swigc1 Traceback (most recent call last): File "<pyshell#0>", line 1, in -toplevel- import swigc1 ImportError: dynamic module does not define init function (initswigc1) Can anybody tell me what is wrong? Thanks in advance, Per Rasmussen.
Every Ptython extension module must export a function named in the form of init<module name>. I've never used SWIG for generating Pyhon extensions, but I assume it should be creating that function for you. Look in the generated source and see if the function exists and was properly exported (__declspec(dllexport)).

Another problem could be calling convention. If your module is C++ rather than C then the initswigc1 function must be declared as:

extern "C" __declspec(dllexport) initswigc1()
{
...
}

Personally, I have found that implementing Python bindings by hand is much more straightforward than messing with tools such as SWIG or Boost::Python. It's dead simple, really. SWIG can sometimes be a PITA.

This topic is closed to new replies.

Advertisement