[cairo] successfully built bindings via SWIG
osmaker+cairo at gmail.com
Tue Mar 18 19:55:59 PDT 2008
I've been wanting to use Cairo with Python for awhile now, but the
Python bindings are a bit out of date.
However, I have successfully built working bindings with SWIG for
Python without having to code much at all (should work with Ruby,
Perl, etc as well). This is based off the trunk from last night.
Relevant code (will need some dir location changes depending on where
you have cairo installed; use pkg-config to find them)...
cairo.i (with preprocessor directives added to cairo's headers, this
file wouldn't be needed):
setup.py (run with python setup.py build_ext -i):
from distutils.core import setup, Extension
setup(ext_modules = [Extension(
"_cairo", # name of output library
["cairo.i"], # swig file
libraries = ["cairo"], # link with cairo lib
Mac OS 10.5 users will need to run setup.py like this (unless you
specifically compiled cairo as a universal binary):
env ARCHFLAGS='' python setup.py build_ext -i
I hope this is helpful. It's probably a lot easier to maintain SWIG
bindings than individual bindings for Java, C#, Perl, PHP, Python,
Ruby, Lua, Scheme, and Ocaml.
More information about the cairo