[python-win32] Cython-generated module crashes after importing C++-extension compiled with MinGW

Christoph Groth cwg at falma.de
Tue Apr 30 01:51:10 CEST 2013


Hi,

We've developed a (BSD licensed) computational Physics package for
Python that is to be released in the coming days.  It works flawlessly
on unixish systems.  I have, however, considerable problems trying to
make it to work under Windows as well.  (I'm using Windows XP SP3 inside
a virtual machine.)

I've managed to make the package actually work, but upon exit of a
Python script that imported it, the following message is shown:

"This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information."

I have managed to bring down the problem to a small test-case,
a directory with three files:

**************** problem.cc ****************
#include <Python.h>
PyMethodDef functions[] = {{0, 0, 0, 0}};

extern "C"
void initproblem()
{
    PyObject* m = Py_InitModule("problem", functions);
}
**************** setup.py ****************
from distutils.core import setup, Extension
module = Extension('problem', language='c++', sources=['problem.cc'])
setup(name='problem', version='0.0', ext_modules=[module])
**************** test.pyx ****************
import problem
********************************

I build and install the package with "python setup.py build" and "python
setup.py install" using the following software:

* Python 2.7.4 from http://python.org/
* MinGW 3.20 (gcc 4.6.2), installed using mingw-get-inst-20120426.exe

This works and the module "problem" _can_ be imported from within a
Python interpreter.  Importing from a cython-generated executable,
however, fails: When I build test.pyx using

cython --embed -a test.pyx    (with Cython 0.19 on linux)
gcc -IC:\Python27\include -LC:\Python27\libs test.c -lpython27   (on windows)

and run the resulting executable a.exe, I get the error message
quoted above.

Strangely, changing "language='c++'" to "language='c'" in setup.py fixes
this problem.  However, this is not a viable solution as it only works
for the toy-example.  (The real module uses C++-features like templates
heavily.  We are using it in our large Python package that contains
Cython-generated modules.)

Does anyone have a clue how this issue could be resolved?  Any help is
greatly appreciated!

Christoph



PS.

Because this problem is very urgent to us, I am posting this to
cython-users at googlegroups.com as well.



More information about the python-win32 mailing list