Sign in to follow this  
perrs

SWIG problem with python

Recommended Posts

perrs    122
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
Aldacron    4544
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this