Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

printz

macrumors regular
Original poster
Dec 23, 2012
218
0
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?
 

ElectricSheep

macrumors 6502
Feb 18, 2004
498
4
Wilmington, DE
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.
 

printz

macrumors regular
Original poster
Dec 23, 2012
218
0
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/.
 

ElectricSheep

macrumors 6502
Feb 18, 2004
498
4
Wilmington, DE
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.