Mac 10.6.8中的Swig和g ++链接错误

时间:2013-03-18 19:37:20

标签: python macos g++ swig

我有一些代码在linux下工作,我现在正在尝试编译Max 10.6.8下的代码。我正在使用EPD 32位python,g ++版本4.2.1,swig版本2.0.9。以下是我正在使用的命令

swig -c++ -python pythoncpp.i
g++ -O2 -fPIC -c  pythoncpp_wrap.cxx -I/PATH/Library/EPD/2.7-32/include/python2.7  -I/PATH/local/gsl/include
g++ -O2 -fPIC -c  pythoncpp_wrap.cxx -I/PATH/Library/EPD/2.7-32/include/python2.7  -I/PATH/local/gsl/include
g++  -L/Users/densmore3/local/gsl/lib -lpython -dynamclib pythoncpp.o pythoncpp_wrap.o -lgsl -lgslcblas -lm -o _pythoncpp.dylib

前三行有错误或警告。但是,链接行会引发以下错误

Undefined symbols:
 "_PyCapsule_Import", referenced from:
  _SWIG_Python_GetModule in pythoncpp_wrap.o
"_PyCapsule_New", referenced from:
  _SWIG_Python_SetModule in pythoncpp_wrap.o
"_main", referenced from:
  start in crt1.10.6.o
"_PyCapsule_GetPointer", referenced from:
  _SWIG_Python_DestroyModule in pythoncpp_wrap.o  
 ld: symbol(s) not found
collect2: ld returned 1 exit status

如何修复此错误?感谢

1 个答案:

答案 0 :(得分:1)

供我将来参考。使用

    ld -bundle -flat_namespace -undefined suppress -L/PATH/local/gsl/lib -lgsl -lgslcblas -lm -o _pythoncpp.so *.o

用于链接所有文件。