Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling C++ with SWIG on Mac OS X [closed]

I am trying to compile a C++ extension using Swig for Mac OS X. I have run into a few linker errors though. The basic tutorial for Python Swig also seems to fail on Mac:

http://www.swig.org/Doc1.3/Python.html#Python_nn10

swig -c++ -python example.i
g++ -O2 -fPIC -c example.cxx
g++ -O2 -fPIC -c example_wrap.cxx -I/usr/include/python2.6
g++ -shared example.o example_wrap.o -o _example.so

The first three lines work fine. The last line fails with a linker error. I tried the last line on OS X with this, and got the same error:

g++ -dynamiclib example.o example_wrap.o -o _example.so

The error from the last line is:

Undefined symbols for architecture x86_64:
  "_PyArg_ParseTuple", referenced from:
      __wrap_fact in example_wrap.o
  "_PyArg_UnpackTuple", referenced from:
      _SwigPyObject_own in example_wrap.o
  "_PyBool_FromLong", referenced from:
      _SwigPyObject_richcompare in example_wrap.o
      _SwigPyObject_own in example_wrap.o
...
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

Thanks.

like image 431
Nick S. Avatar asked Feb 08 '13 23:02

Nick S.


1 Answers

For completeness -- thanks Petesh.

swig -c++ -python example.i
g++ -O2 -fPIC -c example.cxx
g++ -O2 -fPIC -c example_wrap.cxx -I/usr/include/python2.6
g++ -lpython -dynamiclib example.o example_wrap.o -o _example.so
like image 56
Nick S. Avatar answered Nov 13 '22 21:11

Nick S.