I have a .so
file which contains a reference to /Library/Frameworks/Python.framework/Versions/2.7/Python
(I can see this path hard-coded in plaintext within the .so file). I don't have access to the source that built the .so
file.
I'd like to use a different version of the python library (stored in /opt/local/Library
). Is it possible to edit the .so
file to reassign this path?
You may be able to permanently change the reference by using install_name_tool
included with OS X Xcode command line tools.
install_name_tool -change old-lib-path new-lib-path path-to.so
However, if new-path
is longer than the original old-path
, there may not be room in the field in the bundle file (.so) to do so. The man
page for install_name_tool
cautions:
For this tool to work when the install names or rpaths are larger the binary should be built with the ld(1) -headerpad_max_install_names option.
Also, there is no guarantee that the new Python you wish to use was built in a way that is compatible with the old shared library expected by the .so you are trying to modify. There may be differences in universal CPU architectures, OS X deployment targets, and Python build options (for example, UCS-2 vs UCS-4) that may preclude success. You should make a copy of the .so before attempting to modify it.