pythonboostboost-pythonundefined-symbol.so

Why does python throw an undefined symbol error when importing a shared object from an alternate path?


I created a python extension using Boost::Python. To make it easier to use the extension on different target machines, I have included the libboost_python36.so.1.75.0 library in the same directory as the generated extension (pyshmringbuffer.so).

I checked out pyshmringbuffer.so and libboost_python36.so.1.75.0 onto a machine other than it was compiled in the directory : /path/to/pyshmringbuffer

After setting LD_LIBRARY_PATH to: /path/to/pyshmringbuffer and changing to this directory, I am able to run python3.6 and import the shared object just fine.

The problem comes when I try to run python from an alternate directory. From any other directory, I append the python path as follows:

import sys
sys.path.append("/path/to/pyshmringbuffer")

Then, when I try to import pyshmringbuffer, I get the following undefined symbol:

ImportError: /path/to/pyshmringbuffer/pyshmringbuffer.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv

I was under the impression that all symbols are self contained within the shared object. Why does it matter where I import the shared library from?


Solution

  • The symbol in your error message is an internal one, generated by one of the build tools. Having one undefined suggests that one of your components was built with an incompatible tool version, or that a *.so file (shared object) is out of date in some other fashion.

    The simplest way to fix this is usually to rebuild your product components from scratch, in the proper order.