Saturday, 15 October 2016

Swig Python C on Mac

I tried the Swig tutorial without much success. I was getting problems ranging from ugly link time messages:

Undefined symbols for architecture x86_64:
  "_PyArg_ParseTuple", referenced from:
      __wrap_fact in example_wrap.o
      __wrap_my_mod in example_wrap.o
      __wrap_get_time in example_wrap.o
  "_PyArg_UnpackTuple", referenced from:
      _SwigPyObject_own in example_wrap.o

to segmentation faults.

This is what finally worked (for me):

swig -python example.i
gcc -c example.c example_wrap.c -I/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/include/python3.5m
gcc -dynamiclib *.o -o _example.so /usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5m.dylib

Good luck!

Some references:
  • http://stackoverflow.com/questions/10126531/swig-and-c-shared-library
  • http://stackoverflow.com/questions/34803370/swig-wrapping-issues-with-c-python
  • http://stackoverflow.com/questions/14782925/compiling-c-with-swig-on-mac-os-x


1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete