I'm working on developing a macOS dylib framework, developed outside of Xcode, and I'm trying to understand the significance of the install_name
option.
For example, I can set the LC_ID_DYLIB
section name
to something more-like what you would find in a application bundle's framework using the install_name
argument like so.
clang++ ... -install_name @executable_path/../Frameworks/somelib.framework/Versions/somelib ...
Then with otool -l
I can see that my name has been set in the binary, different from the default (which matches the -o
option by default).
otool -l somelib
...
cmd LC_ID_DYLIB
cmdsize 96
name @executable_path/../Frameworks/somelib.framework/Versions/A/somelib (offset 24)
time stamp 1 Wed Dec 31 19:00:01 1969
current version 1.0.0
compatibility version 1.0.0
....
So I understand how to set it, but what I don't understand is what exactly the value is used for to know what it should be, nor can I find any documentation on it.
I can see why the LC_LOAD_DYLIB
sections would need information on where to find a binary (as these sections reference other binaries), but why does a dylib need information on where to find itself? The binary that links against it should be the one that finds it?
So what exactly does a macOS dylib LC_ID_DYLIB
install_name
do?
Any clients that link against the dylib record the path specified in the LC_ID_DYLIB
load command as the path at which to find the dylib at runtime. This is useful as the path where the dylib lives at build time is often not where it will be found at runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With