为 SWIG 指定 Python Headers 和库

Specifying Python Headers and Library for SWIG

我安装了两个 python 版本 2.7 和 3.3。

当我尝试使用 SWIG 1.3.4 生成包装器时,我做了如下操作:

swig -c++ -python -I/opt/rh/python33/root/usr/include/python3.3m mylib.swig

然后,我尝试用 g++ 4.6 编译它

g++ -L/opt/rh/python33/root/usr/lib64 -Wl,-Bstatic -lz -lboost_date_time-mt -Wl,-Bdynamic -lpython3.3m -lbz2 -lpthread -lrt -ldl -O2 -fPIC -shared mylib_wrap.cxx -I.. -I/opt/rh/python33/root/usr/include/python3.3m -I/server/zodiac/include -std=gnu++0x -o _mylib.so

但是,我得到了这样的错误:

mylib_wrap.cxx: In function ‘swig_module_info* SWIG_Python_GetModule()’:
mylib_wrap.cxx:2453:51: error: ‘PyCObject_Import’ was not declared in this scope
mylib_wrap.cxx: In function ‘void SWIG_Python_SetModule(swig_module_info*)’:
mylib_wrap.cxx:2522:92: error: ‘PyCObject_FromVoidPtr’ was not declared in this scope
mylib_wrap.cxx: In function ‘swig_type_info* SWIG_Python_TypeQuery(const char*)’:
mylib_wrap.cxx:2545:60: error: ‘PyCObject_AsVoidPtr’ was not declared in this scope
mylib_wrap.cxx:2550:51: error: ‘PyCObject_FromVoidPtr’ was not declared in this scope

然后,我查看了 Python 2.7 和 3.3 的 headers。我注意到这些表达式是在 Python 2.7 的 headers 中定义的,而不是 3.3.

所以在我看来,即使我在要求 SWIG 生成包装器时指定了 Python 3.3 的包含路径,它仍然尝试使用 2.7.

知道如何解决这个问题吗?

谢谢!

SWIG 1.3.4 很古老。它与 Python 3.3 不兼容。如果您想生成兼容的代码,则需要使用更新版本的 SWIG。