Skip to main content

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

Metadata

Release files for osxrelocator 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for osxrelocator 1.0.1
File Size Uploaded
osxrelocator-1.0.1.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for osxrelocator 1.0.1
File Interpreter ABI Platform
osxrelocator-1.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 12.3 kB

Release files / osxrelocator-1.0.1.tar.gz

Download URL osxrelocator-1.0.1.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cea2a7f58bb8f284adb6b0f13784bd18fbe05a592d696600d40b9c20be06d76d
BLAKE2b-256 checksum
How to use checksums
065e1e28a71cf703add13cb08dde399808b12e0e6b62e118448fd33fd79796ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / osxrelocator-1.0.1-py2.py3-none-any.whl

Download URL osxrelocator-1.0.1-py2.py3-none-any.whl
Size 7.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bebd14adfbbe5f52fec64263d3d787d27e66b9f3507c2269665718ef0c16d517
BLAKE2b-256 checksum
How to use checksums
6f8dcec53820c85aa8afab56202e577f960492ede6a0e8a109bd8cd2714a11f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page