SWIG 导入错误:未定义的符号:_Py_RefTotal

3

我对SWIG非常陌生。我尝试编译SWIG中给出的示例,但出现以下错误:

$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import example
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "example.py", line 25, in <module>
    _example = swig_import_helper()
  File "example.py", line 21, in swig_import_helper
    _mod = imp.load_module('_example', fp, pathname, description)
ImportError: ./_example.so: undefined symbol: _Py_RefTotal
2个回答

3

我遇到了类似的问题,谷歌把我带到了这里 - 我想发表我的解决方案。

对我来说,编译器混淆了是否使用c或c++。

由于我打算写c ++,所以我按照示例使用swing-c ++选项,并将编译器从gcc更改为g ++。

然而,我的构建工具(boost.build或bjam)看到“example.c”,并使用

g ++ -x c -O2 -fPIC -c example.c

“-x c”标志指定c代码,因为bjam根据文件扩展名example.c包含它。 这导致链接类似于求助请求的崩溃。

我将“example.c”的名称更改为“example.cpp”(在使用bjam时删除-x c标志),然后链接就可以正常进行。

我花了一点时间才发现这一点,也许有一天我会节省别人30分钟。

祝福

汤姆


它起作用了。我已经复制并粘贴了相同的代码,然后编译。现在它可以工作了。 - Chenna V

0

你忘记在链接语句中添加 -lpython2.6 了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接