How to build extensions on Windows?

?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Fuzzyman said:
More interestingly, someone reported on Python-dev recently a speed
improvement of around 30% (from memory) by compiling with VC 8. I know
the grumble (almost certainly correctly) about Microsoft's 'odd'
interpretation of the C standards in VC 8, but it looks like there are
major benefits to switching...

You may or may not know that it is futile arguing about compiler
switching for released versions of Python, i.e. 2.3, 2.4, and 2.5.
Whether or not it might be a good idea: it can't be done, for
compatibility with prior releases.

Regards,
Martin
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

John said:
Hi Martin, I do hope you don't regret opening Pandora's box :)

Does the following look about right?

Technically, yes. I wonder whether it will generate unreadable error
messages, though (one would have to try).
I was somewhat bemused by the limit of 200 bytes on the module name in
the error message-- I woild have thought about 20 was more appropriate.
Sorry but I can't test this (Windows box, don't have whatever version
of C compiler is necessary to compile Python).

I'm not sure where this limit comes from, either. This would need to
be researched to find out whether it is just nonsensical, or, if
there is a rationale for it, whether it applies to the path name as
well.

Regards,
Martin
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Fuzzyman said:
Of course, but Python development continues... Into the future..

It's clear that Python can't stay as VS 2003 forever. I don't
know what Microsoft's product plans are, but I hope that we
could skip VS 2005 entirely, and move to VS 2007 for Python 2.6.
That, of course, assumes that there is a VS 2007 release
sufficiently before Python 2.6.

Regards,
Martin
 
L

Lawrence Oluyede

Martin v. Löwis said:
That, of course, assumes that there is a VS 2007 release
sufficiently before Python 2.6.

I just spoke with an MVP for .NET (so nothing official obviously) and he
told me the next VS version will ship after Windows Vista for sure and
that (he mentioned the actual alpha status of the available components)
will be likely in the second half of the year or maybe later.

Anyway after the release of Vista we will all know something more I
guess.

HTH
 
M

michael.hatmaker

Kevin said:
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.

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

michael.hatmaker

Kevin said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top