Python MSVC++ binaries considered evil

eric jones eric at enthought.com
Wed Jan 23 12:11:53 EST 2002


Hello,

We use mingw32 (gcc) on the SciPy project almost exclusively without
problems.  It actually does work for good/stable/complete packages (although
the last couple don't yet describe SciPy -- but that isn't mingw32's
fault...).  The issue is that it takes a little extra effort to build gcc
extensions that work with the binary Python distributions from python.org or
ActiveState which were compiled with MSVC.  The main difficulty is making
the python21.lib file (or whatever version you are using) in the
C:\Python21\libs directory to a libpython21.a library needed by gcc.  If you
build Python from scratch with mingw32 (which I've never done, but feel
certain that it is possible), then you don't need to jump through this hoop.

Information about how to build extensions with mingw32 is provided by Robert
Kern here:

http://starship.python.net/crew/kernr/mingw32/Notes.html

It is somewhat dated, but the general ideas all hold.  Robert also provides
a tool called lib2def.py for helping build a libpython21.a file from
python21.lib.  It actually was written for 1.52 or something like that, so
you'll have to do some hacking.

If your using distutils, the easiest path might be to grab the
scipy_distutils package from the SciPy CVS, or optionally from its nightly
build here:

ftp://www.scipy.org/pub/scipy_snapshot.tgz

scipy_distutils is an extension to distutils that we use for building SciPy.
Among many other things (like Fortran and f2py support), it has a hacked
mingw32_compiler class that automatically builds the libpython21.a file if
it doesn't currently exist.

If you put

if sys.platform == 'win32':
    from scipy_distutils.mingw32_support import *

at the top of a setup.py file, mingw32 will automatically be used on
windows.

So, using a free compiler does not fall in the "impossible" or "bad idea"
category, but rather in the "it takes some extra work" category.  Hopefully
the links will be helpful.

eric

ps:  mingw32 and MSVC are *not* binary compatible for C++ libraries.  This
does not mean you can't use gcc compiled C++ extensions in an MSVC compiled
Python.  On the contray, they work fine.  The problem comes when you want to
build a C++ extension with mingw32 that links to a C++ library built with
MSVC.  This will cause smoke and flames.  An example of when you might want
to do this is building a wxPython extension with gcc that links with the
pre-compiled binaries for wxPython provided by Robin Dunn which are built
with MSVC.  This will link, but cause seg-faults.  The solution is either to
get MSVC or build wxPython and wxWindows from scratch using mingw32.  I've
never tried the latter.

----- Original Message -----
From: "J.Jacob" <joost_jacob at hotmail.com>
Newsgroups: comp.lang.python
Sent: Wednesday, January 23, 2002 7:25 AM
Subject: Re: Python MSVC++ binaries considered evil


> [John Machin]
> > False. You can make DLLs using the Borland or MinGW compiler.
> > ...
> > [snipped: more erroneous conclusions based on false premises]
> > ...
> > BTW, there *is* documentation (in the Python manuals!) for extending
> > Python with the non-MS compilers on Windows ...
>
> If you try to build DLLs with Borland or MingW for any serious work
> you will find this route does not lead to a good / stable / complete
> product.  Review the premises.  Ask any professional developer, you
> need to use the MSVC++ as it is now.
>
> The documentation about non-MS compilers is erm...lets say not
> sufficient





More information about the Python-list mailing list