Chenna V
Chenna V

Reputation: 10513

SWIG ImportError: 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

Upvotes: 3

Views: 3657

Answers (2)

John Greene
John Greene

Reputation: 2606

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

Upvotes: 0

Tom
Tom

Reputation: 76

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

Upvotes: 3

Related Questions