How to build extensions on Windows?

michael.hatmaker at gmail.com michael.hatmaker at gmail.com
Fri Sep 15 12:43:40 EDT 2006


michael.hatmaker at gmail.com wrote:
> Kevin D. Smith wrote:
> > I've written a simple Python extension for UNIX, but I need to get it
> > working on Windows now.  I'm having some difficulties figuring out how
> > to do this.  I've seen web pages that say that MS Visual Studio is
> > required, and other that say that's not true, that MinGW will work.
> > Then there is Mike Fletcher's web page
> > (http://www.vrplumber.com/programming/mstoolkit/) that describes in
> > detail how to build extensions, but most of the links to external
> > software are no longer valid.  I think it's safe to say that I am
> > completely lost, as there appears to be no authoritative, up-to-date
> > description on how to make this work.
> >
> > --
> > Kevin D. Smith
>
> Borland released a free version of their C++ compiler and IDE on 9/4,
> coinciding with my need to move my GeoTrans extension from Linux to
> Windows.  I didn't need the IDE for the project, since my
> GeoTransMethodsSetup.py script from Linux worked fine, running it with
> the command line argument "--compiler=bcpp".  Add paths to the include
> directories and library directories.
>
> The biggest headache was a bunch of nonsense linker error messages,
> which turned out to be because I had made the mistake of installing the
> compiler under "Program Files", and setup does not behave well with
> spaces in the path name.  As a quick work-around, I used the DOS 8.3
> filename.  Next time I will install Borland in a path with no spaces in
> the name.  So, I was able to use a state-of-the-art compiler, rather
> than work with an obsolete version of some compiler relic.
>
> from distutils.core import setup, Extension
> GeoTransMethods = Extension('GeoTransMethods',
> 				include_dirs = ['C:\python24\include'],
> 				library_dirs = [
> 				r"C:\PROGRA~1\Borland\BDS\4.0\lib",
> 				r"C:\PROGRA~1\Borland\BDS\4.0\lib\release",
> 				r"C:\PROGRA~1\Borland\BDS\4.0\lib\obj",
> 				r"C:\PROGRA~1\Borland\BDS\4.0\lib\PSDK",
> 				r"C:\PROGRA~1\Borland\BDS\4.0\lib\Indy9"],
> 				sources = ["GeoTransMethods.c", "mgrs.c", "utm.c", "ups.c",
> "tranmerc.c", "polarst.c"])
>
> setup(name="GeoTransMethods", version="1.0",
>       ext_modules=[GeoTransMethods])

I neglected to mention another detail.  There are a number of postings
around regarding earlier Borland compilers.  There is a brief overview
at http://docs.python.org/inst/tweak-flags.html
It mentions the necessity of converting the object file format (COFF)
of python libraries built with Visual C++ to Borland's OMF object file
format.  You need to download coff2omf and run it to make
Borland-linkable copies of python24.lib and any other VC++ built libs,
such as zlib:

coff2omf python24.lib python24_bcpp.lib

Distutils run with the bccp compiler option will look for _bccp
versions and use them before attempting to use the VC++ versions.




More information about the Python-list mailing list