我正在尝试使用 Swig for Mac OS X 编译 C++ 扩展。不过,我遇到了一些链接器错误。Python Swig 的基本教程在 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
前三行工作正常。最后一行因链接器错误而失败。我用这个在 OS X 上尝试了最后一行,得到了同样的错误:
g++ -dynamiclib example.o example_wrap.o -o _example.so
最后一行的错误是:
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
谢谢。