Partially Attended

an irregularly updated blog by Ian Mulvany

wrapping c code for python using swig on Mac OS X

Wed Jan 21, 2009

62 Words
from john d cook
http://www.johndcook.com/blog/2009/01/20/using-swig-to-expose-c-code-to-python/

from
http://www.penzilla.net/tutorials/python/swig/

and combining the two I came up with a way to get this to work on Mac OS X

bash$ cat erf.i

%module erf
#include
double erf(double);

bash$ swig -o erf_wrap.c -python erf.i
bash$ gcc -o erf_wrap.os -c -fPIC -I/usr/include/python2.4 erf_wrap.c
bash$ gcc -o _erf.so -shared erf_wrap.os
bash$ python
>>> from erf import erf
>>> erf(1)
0.84270079294971489
This work is licensed under a Creative Commons Attribution 4.0 International License