SWIG ImportError: undefined symbol: _Py_RefTotal

丶灬走出姿态 提交于 2019-12-11 03:49:55

问题


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

回答1:


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




回答2:


You forgot to add -lpython2.6 to your linker statement.



来源:https://stackoverflow.com/questions/3480995/swig-importerror-undefined-symbol-py-reftotal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!