building extensions for Windows Python
Nick Craig-Wood
nick at craig-wood.com
Sat Oct 14 01:33:51 EDT 2006
JW <wilson1442 at bellsouth.net> wrote:
> I have a lousy little Python extension, generated with the generous help
> of Pyrex. In Linux, things are simple. I compile the extension, link it
> against some C stuff, and *poof*! everything works.
;-)
> My employer wants me to create a Windows version of my extension that
> works with the vanilla Python 2.5 from python.org.
>
> My employment contract states that I won't be required to run Windows, and
> I desperately want to honor that clause. Ideally, I'd somehow MinGw cross
> compile like I do with C/C++ and *poof*!, out would pop a file I could
> hand out to someone who wanted to "import <my_lousy_extension>".
You can do that no trouble - we do. We use mingw on linux to compile
stuff for windows all the time. (We use the mingw package under
debian)
We build extensions using mingw but linked to the link library of the
official python2.4 build. The extensions then run with the standard
python.org install.
Here are some (slightly dated) instructions which you'll need to adapt
to your setup
/misc/windows is a smb mounted windows machine
# Linking with the distributed python
#
# http://bonsai.ims.u-tokyo.ac.jp/~mdehoon/software/python/cygwin.html
#
# On a windows machine
# install the latest windows python (2.4.3.msi) from www.python.org
# Copy the header files into the mingw installation
cp -av /misc/windows/Python24/include /usr/i586-mingw32msvc/include/python2.4
# Download pexports from here
# http://www.emmestech.com/software/cygwin/pexports-0.43/download_pexports.html
# unpack pexports.exe
unzip pexports-0.43.zip
# Fetch python dll from the windows machine
cp -av /misc/windows/WINNT/system32/python24.dll .
# Extract the exported symbols
wine pexports python24.dll > python24.def
# Create the link library
/usr/i586-mingw32msvc/bin/dlltool --dllname python24.dll --def python24.def --output-lib libpython2.4.a
# Move the files into the correct place
mv -i python24.dll python24.def libpython2.4.a /usr/i586-mingw32msvc/lib/
After that lot you can build python extensions with mingw under linux,
using -lpython2.4 which will run under windows.
--
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick
More information about the Python-list
mailing list