Question

I have a working c++ code that I want to wrap into a python module on Windows XP and Python 2.7. I have never done this before, so I looked into swig and distutils.

I created an interface file and a setup.py and compiled using

python setup.py build_ext -c mingw32

The script creates a module_wrap.cpp from my module.i and module.cpp file, and then creates a module_wrap.o and a module.o. The creation of module.o creates a bunch of Warnings for unused variables and deprecated char*, but it seems to work. Because the C++-code is not mine, I don't really want to get into these right now.

The last step is executing

g++.exe -shared -s build\temp.win32-2.7\Release\module_wrap.o build\temp.win32-2.7\Release\module.o build\temp.win32-2.7\Release\_module.def -LC:\Programme\Python27\libs -LC:\Programme\Python27\PCbuild -lpython27 -o build\lib.win32-2.7\_module.pyd

I get

Cannot export init_module: symbol not defined
error: command 'g++' failed with exit status 1

I googled a lot to this now, and I just can not find a solution to this problem. The previously created _module.def seems to try to export this init since it contains

LIBRARY _module.pyd
EXPORTS
init_module

Obviously this doesn't work, but I have no idea why. Can anyone help me out here?

Was it helpful?

Solution

I figured it out. The problem was the (not posted) interface file module.i for swig. There I named the module %module usemodule, whereas in the setup.py i named the module name=module. This way swig created an init_function, that did not match the name the created module was expecting it. In the end: just a typo...

Thanks for your support nevertheless!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top