Skip to content

Instantly share code, notes, and snippets.

@wware
Last active November 28, 2016 15:58
Show Gist options
  • Save wware/9ecd5fedf7d2dd335d4464584d8e03d9 to your computer and use it in GitHub Desktop.
Save wware/9ecd5fedf7d2dd335d4464584d8e03d9 to your computer and use it in GitHub Desktop.
Reminder of how to use SWIG to wrap C functions for use in Python
Do this:
make
gdb -x hook.x `which python`
More info: http://www.swig.org/Doc1.3/Python.html
void wware_hook(void)
{
return;
}
%module hook
%{
void wware_hook(void);
%}
void wware_hook(void);
set breakpoint pending on
break wware_hook
run hook2.py
import hook
hook.wware_hook()
all: _hook.so
wrapper.c: hook.i
swig -python -o wrapper.c hook.i
wrapper.o: wrapper.c
gcc -I/usr/include/python2.7 -fPIC -c wrapper.c
hook.o: hook.c
gcc -fPIC -c hook.c
_hook.so: hook.o wrapper.o
gcc -shared wrapper.o hook.o -lpython2.7 -o _hook.so
clean:
rm -f wrapper.c wrapper.o hook.o hook.so _hook.so hook.py hook.pyc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment