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

Graham Bloice graham.bloice at trihedral.com
Tue Apr 30 10:16:24 CEST 2013


> -----Original Message-----
> From: python-win32 [mailto:python-win32-
> bounces+graham.bloice=trihedral.com at python.org] On Behalf Of Christoph
> Groth
> Sent: 30 April 2013 00:51
> To: python-win32 at python.org
> Subject: [python-win32] Cython-generated module crashes after importing
> C++-extension compiled with MinGW
>
> 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!
>
[Graham Bloice said]

Can you mix compilers with Python extensions, I thought you should (must)
use the same compiler as the version of Python you are using is built with
due to the compiler run-time library being used?  See
http://docs.python.org/2.7/extending/windows.html#using-dlls-in-practice


More information about the python-win32 mailing list