• Advertisement
Sign in to follow this  

SWIG problem with python

This topic is 4946 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement