SWIG ImportError:未定义的符号:_Py_RefTotal
我对 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
I am really new to SWIG. I tried to compile the example given in SWIG but I get the following error:
$ 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的问题,谷歌将我发送到这里 - 我想我会发布我的解决方案。
对我来说,编译器对于是使用 c 还是 c++ 感到困惑。
由于我打算编写 c++,因此我遵循了该示例,但使用了 swing -c++ 选项,并使用 g++ 而不是 gcc 作为编译器。
然而,
我的构建工具(boost.build 或 bjam)看到“example.c”并使用
g++ -xc -O2 -fPIC -c example.c
进行编译。“-x c”标志指定 c 代码,bjam 包含该代码是因为文件扩展名为 example.c。这导致链接以与帮助请求类似的方式发出嘎嘎声。
我将“example.c”的名称更改为“example.cpp”(使用 bjam 时删除了 -xc 标志),然后链接继续正常进行。
我花了一点时间才发现这一点,所以也许有一天我可以为某人节省 30 分钟。
祝福
汤姆
I had a similar problem and google sent me here - I thought I would post my solution.
For me the compiler was getting confused as to whether to use c or c++.
Since I intend to write c++ I followed the example but used the swing -c++ option and used g++ rather than gcc as the compiler.
However,
my build tool (boost.build, or bjam) was seeing "example.c" and was compiling with
g++ -x c -O2 -fPIC -c example.c
The "-x c" flag specify c code, which bjam included because of the file extension to example.c. This caused the linking to croak in a similar manner to the help request.
I changed the name of "example.c" to "example.cpp" (which removes the -x c flags when using bjam) and the linking then proceeded okay.
It took me a little while to spot this, so maybe I will save somebody 30 minutes one day.
Blessings
Tom
您忘记将
-lpython2.6
添加到链接器语句中。You forgot to add
-lpython2.6
to your linker statement.