View Full Version : Change a binary's dependency paths?
Aug 5, 2013, 10:48 AM
I know that with 'otool -L' I can list a binary file's libraries it depends on. Is there a way to change its library search paths? I know I can already change a library's install name with install_name_tool. Can I do the same with the library search paths?
Aug 5, 2013, 01:45 PM
You can export colon-separated lists of paths to DYLD_FRAMEWORK_PATH and/or DYLD_LIBRARY_PATH environment variables to specify what directories should be searched first for Frameworks and Libraries. This allows you to test new versions of frameworks and libraries without having to install them to the standard search paths.
Aug 6, 2013, 04:29 AM
Yeah but I want to change an alreadily built binary's search paths. Like for example it depends on some dylibs located in /opt/local/bin/. I want it to depend on those same files, but located in @loader_path/.
Aug 6, 2013, 07:18 AM
And that is what those environment variables can allow you to do. For example, I have a version of python built via MacPorts which is staged in /opt/local/. Normally, it will search for Frameworks and dylibs in /opt/local/Library/Frameworks/ and /opt/local/lib to bind at runtime.
Setting the environment variable DYLD_PRINT_LIBRARIES causes dyld to print a dump of all the frameworks and libraries bound at runtime to verify what is actually being loaded from where. Normally, my MacPorts python would load ncurses from /opt/local/lib/libncurses.5.dylib. If I setenv DYLD_LIBRARY_PATH /usr/lib/ and execute my MacPorts python again, it loads ncurses from /usr/lib/libncurses.5.4.dylib.
See the manpage for dyld for more environment variables that you can use to manipulate how dylibs and frameworks are loaded at runtime.