Reputation: 103
I have an existing bundle/executable, which I need to add a new dylib into.
Methods I've already tried:
Copying dylib into bundle & setting dyld_insert_libraries within info.plist to load library. This works with the one issue that I won't be able to control the location of the app/bundle (or library if outside bundle) and relative paths (e.g @executable_path) can't be used in info.plist.
Using install_name_tool (-add_rpath, -id, etc) to add a new path to the library. This just doesn't seem to work unless theres a path in there to change. (The name/install location of the library is correct and been checked many times).
Are there any further solutions to this problem or even modifications on the solutions (above) that I've already tried?
Upvotes: 3
Views: 2014
Reputation: 30102
I've made a tool that can do that called insert_dylib
: https://github.com/Tyilo/insert_dylib
Here's the usage info:
Usage: insert_dylib [--inplace] [--weak] dylib_path binary_path [new_path]
And how to use it:
$ insert_dylib /usr/lib/libfoo.dylib test
The provided dylib path doesn't exist. Continue anyway? [y/n] y
Added LC_LOAD_DYLIB command to test_patched
$ diff -u <(otool -hl test) <(otool -hl test_patched)
...
Upvotes: 3
Reputation: 1009
You can also set the environment variable DYLD_INSERT_LIBRARIES to point the library you want to inject when executing the binary. See https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man1/dyld.1.html for details.
Upvotes: 0