How to build extensions on Windows?

michael.hatmaker at gmail.com michael.hatmaker at gmail.com
Fri Sep 15 03:21:18 CEST 2006


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])




More information about the Python-list mailing list