简体   繁体   中英

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?

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.

I was able to resolve my issue by prepending /path/to/pyshmringbuffer to my python path using:

sys.path.insert(0,"/path/to/pyshmringbuffer")

I can't say for sure, but as @PRUNE pointed out, there is something in my python path that python is seeing before it sees the intended library.

Coincidentally, I DO have a build of libboost_python36.so.1.75.0 located elsewhere on the target machine. The path for this doesn't appear on my PYTHONPATH or LD_LIBRARY_PATH, so I wouldn't EXPECT it to have been interfering, but I can't be positive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM