[python-win32] Building extensions with non-MSVC compilers

David Rushby davidrushby at yahoo.com
Sun Oct 31 20:56:39 CET 2004


--- Paul Moore <p.f.moore at gmail.com> wrote:
> On Sun, 31 Oct 2004 17:18:42 +0100, Mauro Cicognini
> <mcicogni at libero.it> wrote:
> > Hi everybody,
> > I've tried to Google for all past references to the subject, 
> > but I could not find any conclusive answer to my real question,
> > which is "Will a mingw-built extension work with a standard 
> > MSVC-built Python interpreter?"
> 
> Yes. If you use distutils, --compiler=mingw is supported. See the
> "Installing Python Modules" manual, section 6.2.2 for the details...

The aim of the process described there is to create a GCC-compatible
equivalent of the MSVC library "pythonVV.lib" (where VV would be 23 for
Python 2.3), typically named "libpythonVV.a" and placed in the same
directory as "pythonVV.lib".  I got tired of repeating the process with
different versions of Python and MinGW, so I automated the process in
this script:
  http://kinterbasdb.sourceforge.net/other/cext/mingw_support.py

The "pexports" tool that the script uses is in MinGW's mingw-utils
package, and "dlltool" is in the binutils package.

The intent is that mingw_support.py can be included alongside setup.py
in the source distribution of a Python C extension, and setup.py can
call 'import mingw_support; mingw_support.generateMinGWPythonLib()'
during the build process to ease the experience of an end user
compiling the extension with MinGW rather than MSVC.

---

I don't know whether OpenLDAP or its Python wrapper include any C++,
but if so, beware of this irritating bug when you attempt to build with
mingw:
 
http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=877165

That's fixed in CVS, which is reflected in Python 2.4b1, and should
also be fixed in Python 2.3.5.

---

The GCC compiler itself executes slowly compared to most commercial
compilers (including MSVC), but the quality of the code generated by
the latest versions of GCC is pretty good.

I've written several processor-bound Python extension modules (I'm not
referring to kinterbasdb, which is not processor-bound), and have been
pleasantly surprised by the performance of GCC 3.4 versus MSVC 6.0 and
7.1.

In one integer-intensive C code base, the speed of code compiled with
MinGW GCC 3.4.2 (with aggressive optimization settings
"-mtune=athlon-xp -DNDEBUG -O3 -fmove-all-movables -freduce-all-givs
-ftracer -fomit-frame-pointer -ffast-math") surpasses MSVC 6.0 by 17%,
and MSVC 7.1 by 10%.

In a much larger and more diverse C++ code base (still
integer-intensive, and compiled with the same optimization settings),
GCC 3.4.2 ties with MSVC 7.1 unless MSVC 7.1's link-time code
generation is enabled, in which case MSVC is 10% faster.  The link-time
code generation in MSVC 7.1 seems pretty buggy, though, so it's not
always a viable option.

The size of GCC-generated binaries is consistently larger than that of
MSVC binaries, especially if C++ is involved.  For whatever reason,
MinGW doesn't use Microsoft's C++ runtime library by default, and
licensing constraints complicate the non-static use of the GNU version,
so MinGW statically compiles any required STL code into the .pyd
(http://www.mingw.org/mingwfaq.shtml#faq-C++size ).  The MinGW .pyd
from the C++ code base I spoke of is more than twice as large as its
MSVC equivalent.

It's worth noting that the "free" command-line version of MSVC 7.1
(http://msdn.microsoft.com/visualc/vctoolkit2003/ ) can be made to
compile and link both C and C++ extensions with Python 2.4, if you're
willing to go to a lot of trouble:
  - Downloading and installing the .NET 1.1 runtime and .NET SDK.
  - Downloading and installing the huge Windows Platform SDK, which has
a particularly annoying through-the-web, IE-only installer (this can be
circumvented and the files saved for offline installation).
  - Overriding distutils' insistence that the full version of VStudio
2003 be installed.
  - Using the msvcrt.lib from the Platform SDK (msvcrt.lib is not
included with the command-line version of MSVC 7.1).
  - Generating msvcprt.lib on the basis of msvcp71.dll (msvcprt.lib is
also not included with the command-line version of MSVC 7.1).


		
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 


More information about the Python-win32 mailing list