Windows versions of Python---pros and cons?

Frédéric Cordonier fcordonier at
Fri Jun 21 10:22:13 CEST 2002

Gerhard Häring wrote:

>* Trent Mick <trentm at> [2002-06-19 15:46 -0700]:
>>My understanding is that for C extensions to work they must be built
>>with the same compiler as that used to build the Python with which they
>>will run. (I may be wrong. Someone please correct me if I am.)
>You are wrong. As long as you link to the python{major}{minor}.dll you
>are binary compatible, no matter which compiler you use. It's just a
>matter of providing an additional compiler option to distutils, like in:
>    python build --compiler=mingw32

I am no windows or C++ specialist, but I happened to write extensions 
for Python in the scope of unitary testing code for embedded systems.

I did extensions with both Borland C++ 5.01 and mingw32. Under windows, 
it is always easier to link the project with a .lib file rather than 
directly connecting to the .dll. The problem with Borland is that the 
.lib for Pythonxx.dll is tricky to generate. In fact, Borland adds some 
'_' to the exported symbols.  You have to:
 > impdef Python22.def Python22.dll

modify the Python22.def to add leading '_' to the symbols (I use gvim 
that is really handy for this kind of tasks).

 > implib Python22.lib Python22.def

For Mingw32, the .lib file can be generated with 'pexports' and 'dlltool'.

Moreover, I wrote extensions with SWIG using Borland. One problem I 
encountered is that the main module entry is not exported correctly 
(when importing the module, an exception is raised), because SWIGEXPORT 
is not adapted (maybe specific to BC++5.01?).
You have to redefine it to
#define SWIGEXPORT(a)   a _export FAR PASCAL

Last, using distutil with Borland is certainly possible, but not with 
version 5.01 (my customer only has this version). Some linker options 
used with '--compler=bcpp' are not known by 5.01. I had to patch 
distutils to make it work. If ever someone needs it, I will go back to 
my notebook to check what was done...


More information about the Python-list mailing list