Compiling Python Extensions w/ Mingw32
It is an unpleasant fact that there is no Python binding for FreeType 2— the one I had discovered is apparently very outdated, and not being worked on. Since I thought I’d at least look into the possibility of binding it myself; looking at the code for that one, it doesn’t look like too daunting a task: tedious, but not requiring any tricks. So I figured, if I concentrate on just the portions of the API I need, I should be able to handle this.
First, I had to get a copy of Mingw32; luckily for me, it turns out that comes bundled in the Enthought Python distribution, so I was saved the hassle of a 49Mb download over a dial-up connection. This morning I spent about 2 hours searching on the Internet and wrestling at the command line trying to figure out how to compile C extensions for Python. That was an unpleasant reminder of why I dislike C programming so much, especially under Windows: all the switches, and linking, and worrying about library types and versions; and despite all the care in the world and careful adherence to instructions, nothing ever works right. Nontrivial C programming has always been like black magic to me. And after all that, I discover that what I needed to do was very simple:
- Open up python, and run
[python]
from scipy_distutils.mingw32ccompiler import *
build_import_library()
[/python] - Make my extension’s dll by calling
gcc hello.c -IC:\Python23\include -Lc:\python23\libs -lpython23 -shared -o hello.dll
And that’s it. I don’t know what distutils is, but it seems to be the standard for installing extensions, so maybe it’s worth looking into more. Also, once I build the library with the function call, it remains in the library directory, so I need do the first step only once.
Now I need to figure out SWIG, and the Freetype API.