Utility to relocate OSX libraries
Project description
Installation
pip install osxrelocator
Usage
osxrelocator.py [options] directory old_prefix new_prefix
Description
On Darwin operating systems, the dynamic linker doesn’t locate dependent dynamic libraries using their leaf name, but instead it uses full paths, which makes it harder to relocate them as explained in the DYNAMIC LIBRARY LOADING section of dyld’s man page:
> Unlike many other operating systems, Darwin does not locate dependent dynamic > libraries via their leaf file name. Instead the full path to each dylib is > used (e.g. /usr/lib/libSystem.B.dylib). But there are times when a full path > is not appropriate; for instance, may want your binaries to be installable in > anywhere on the disk.
We can get the list of paths used by an object file to locate its dependent dynamic libraries using otool:
$ otool -L /Library/Frameworks/GStreamer.framework/Commands/gst-launch-0.10 /Library/Frameworks/GStreamer.framework/Commands/gst-launch-0.10: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.43.0) /Library/Frameworks/GStreamer.framework/Versions/0.10/x86/lib/libgstreamer-0.10.0.dylib (compatibility version 31.0.0, current version 31.0.0) /Library/Frameworks/GStreamer.framework/Versions/0.10/x86/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.8.0)
This full path is extracted from the dynamic library install name, a path that is used by the linker to determine its location. The install name of a library can be retrieved with otool too:
$ otool -D /Library/Frameworks/GStreamer.framework/Libraries/libgstreamer-0.10.dylib /Library/Frameworks/GStreamer.framework/Libraries/libgstreamer-0.10.dylib: /Library/Frameworks/GStreamer.framework/Versions/0.10/x86/lib/libgstreamer-0.10.0.dylib
Any object file that links to the dynamic library gstreamer-0.10 will use the path /Library/Frameworks/GStreamer.framework/Versions/0.10/x86/lib/libgstreamer-0.10.0.dylib to locate it.
Since working exclusively with full paths wouldn’t let us install our binaries anywhere in the path, the linker provides a mechanism of string substitution, adding three variables that can be used as a path prefix. At runtime the linker will replace them with the generated path for the prefix. These variables are @executable_path, @loader_path and @rpath, described in depth in the DYNAMIC LIBRARY LOADING section of dyld’s man page.
For our purpose we will use the @executable_path variable, which is replaced with a fixed path, the path to the directory containing the main executable: `/Applications/MyApp.app/Contents/MacOS. The @loader_path variable can’t be used in our scope, because it will be replaced with the path to the directory containing the mach-o binary that loaded the dynamic library, which can vary.
Therefore, in order to relocate the SDK we will need to replace all paths containing /Library/Frameworks/GStreamer.framework/ with @executable_path/../Frameworks/GStreamer.framework/, which can be done using the install_name_tool utility
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file osxrelocator-1.0.0.tar.gz
.
File metadata
- Download URL: osxrelocator-1.0.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b2f452e1da1987bad73c927c0842ca0276d3ac451188fcbb0e87a157d2bb2ba |
|
MD5 | 104fcbe22a841db83b0fc0eac27391a1 |
|
BLAKE2b-256 | 96c102c1d6694c8dc3da9288d2e3b56d759af50368c9034039a320e238f7e63c |
File details
Details for the file osxrelocator-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: osxrelocator-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2934a94f04de58d69944763cd113ac5ddb8c96fc9f0fa3bbddaf0bfe218ca4e0 |
|
MD5 | 3117edc8a43daa41a0e4c0e75b4ba454 |
|
BLAKE2b-256 | abf8598a16dcd7d0d478e39e21361ceeb160eceb01fe5996c3ca054bbf5df2e5 |