c++ - 为 SWIG 指定 Python header 和库

标签 c++ linux python-3.x python-2.7 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 的 header 。我注意到这些表达式是在 Python 2.7 的 header 中定义的,但在 3.3 中没有定义。

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

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

谢谢!

最佳答案

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

关于c++ - 为 SWIG 指定 Python header 和库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49695001/

相关文章:

c++ - move 对象 (OpenGL)

c++ - OpenSSL : Encrypt a symmetric key with an ECC public key

linux - 安装Centos 7时出现未知错误

php - Crontab Linux 未在特定时间运行

python - argparse add_argument 来自字典

python-3.x - 如何将基于 "None"距离的Dijsktra算法的Python实现转换为 "Infinity"距离

python-3.x - 使用 conda 4.3.21 为 python 3.6 安装 pybox2d

c++ - 迭代地编写递归代码

C++模板继承看不到基类成员

regex - Bash - 如何将每一行放在引号内