..
index
nget
id3ed
alarmwatch
cfv
fchksum
par2ls
gvidm
libglfps
rmdirr
*py-ext-cross* | Some Random Babbling
Up until now, there has not been much/any information on the web about cross compiling python modules.
I hope to rectify (at least a sub-set of) that problem.
This page focuses on cross-compiling on a linux host to a win32 target, using the mingw32 cross-compiler. (If you run debian, simply apt-get install mingw32.)
The information was mainly gleaned from Instructions for Python Extensions with GCC/mingw32 which focuses on building modules with the win32 native mingw32 compiler.
In addition, all the files available there are only for Python 1.5.
Ideally, one could just specify some sort of cross-compilation arg to distutils.
However (as of Python 2.3), no such option exists.
Therefore, we will have to make do with a Makefile.
There are 3 general things that must be taken into account when cross-compiling:
- Using the cross-compiler and related tools instead of the standard ones.
- Using the target's libraries and includes instead of the host's.
- Mingw32 specific: mingw32 doesn't accept the .lib files that are included in the standard win32 python distribution.
A slightly modified version of the lib2def.py script from the previously mentioned page is needed to solve this one.
The Meat
- First, get the Python win32 installer.
You can either install it on an existing windows partition(dual-boot), with vmware, wine, or just extract the relevant bits with unzip.
- Grab my updated lib2def.py, example Makefile, and example .def file.
- Modify the neccessary bits in the makefile:
- CC, NM, DLLWRAP, DLLTOOL: The cross-compiler and its tools.
- PYVER: The target version of python, in <MAJOR><MINOR> form.
- PYDIR: Where you installed the target version of python.
- INCLUDES, LDFLAGS, LIBS: You can add additional libraries here, if needed.
- MODULE: Your extension module name.
- INPUT: The object files which make up your module.
- Other variables: Probably shouldn't need modification.
- Modify the .def file: Put in your module's name, give the file the correct name.
- Cross fingers and run make -f mingw32-cross.mak
Notes
The information on this page has been successfully used with Python2.3 and Mingw32 api 2.3 / gcc 3.2.1.
Your milage may vary.
Comments may be directed to: Matthew Mueller <donut AT dakotacom DOT net>.
Last Update: 2006-04-05 19:13:43 PDT | Last Edit: 2003-08-23 17:55:05 PDT
frames|tables|simple |