Opened 14 years ago
Closed 14 years ago
#1927 closed Bugs (fixed)
MacOS (Darwin) should use the -headerpad_max_install_name option
Reported by: | Owned by: | René Rivera | |
---|---|---|---|
Milestone: | Boost 1.36.0 | Component: | build |
Version: | Boost 1.35.0 | Severity: | Problem |
Keywords: | darwin macos library dylib | Cc: |
Description
Because of the way that dynamic linking works on MacOS, to be able to redistribute dynamic libraries it is necessary to include the path to the library in the executable.
Attached is a patch (from the MacPorts people) to make relocation much, much easier using MacOS's 'install_name_tool'.
Attachments (1)
Change History (8)
by , 14 years ago
Attachment: | patch-tools-build-v2-tools-darwin.jam added |
---|
follow-up: 2 comment:1 by , 14 years ago
I cannot find any information about this option in google. Can you either point me at option's doc, and explanation why it's necessary, or describe it yourself?
Thanks.
comment:2 by , 14 years ago
Sure - sorry, you couldn't google it because I was missing an 's' (the patch-file is fine, my bug summary missed the letter).
From the Apple 'ld' linker man page:
-headerpad_max_install_names (32-bit only) Add to the header padding enough space to allow changing all dynamic shared library paths recorded in the output file to be changed to MAXPATHLEN in length.
(The option is not needed for 64-bit objects, and is silently ignored.)
Basically, when creating shared objects, the apple linker places a semi-absolute pathname of the library and all dependent dynamic objects into the object. Think of it as the apple 'solution' to Linux's ld.so conf file. To see the paths of embedded objects, use "otool -L". To change the embedded path name, use "install_name_tool".
It is the changing-part that needs the header padding. Suppose I build boost and install it into /opt/local. Then all the libraries reference themselves (and any other required libs) as '/opt/local/lib/libboost-blah.dyld'. If I want to redistribute my software binaries plus libraries, I need to rename the internal name of the libraries.
Without the headerpad option to the linker, the new path must be equal or shorter in length than the old path. Blech! With the headerpad option, I can use any valid filesystem path.
Thus, building redistributable binaries in boost is only practical on darwin with this option.
Yes, it is a kludge... and that's why apple fixed it for the 64-bit sub-file-format.
Cheers, -Andrew.
follow-up: 4 comment:3 by , 14 years ago
Do you mean that on OSX, it is the standard practice to embed full path to dependency libraries into shipped applications? Is each application supposed to be installed into a fixed location?
comment:4 by , 14 years ago
The short, but inaccurate answer, is "yes".
Dynamic library paths and linking on Apple is not as simple topic. Libraries (inside frameworks) are usually in fixed locations. There is (under 10.4) a "magic" file name so libraries can be located with respect to the executable file bundle.
Apple has extensive documentation on how dyld files are searched for.
A brief (and informative) summary is here.
Leopard (10.5) introduced RPATH semantics see here.
But basically... using the "-headerpad_max_install_names" linker option allows the boost user to compile boost once and then package up the libraries as "application-specific framework bundles" in a final application. Without the headerpad option, boost must be custom-compiled to its final installation directory for every project that uses it.
follow-up: 6 comment:5 by , 14 years ago
Component: | Building Boost → build |
---|---|
Milestone: | Boost 1.35.1 → Boost 1.36.0 |
Owner: | set to |
Status: | new → assigned |
comment:6 by , 14 years ago
comment:7 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixed in rev [46793], along with other cleanups.
add header padding to the dylib