Take the 2-minute tour ×

I'm working on a private framework for OSX 10.6 which includes some command line tools as well as some dylibs. Now, the dylibs need to link against each other and the command line tools need to link against the dylibs.

The command line tools and the .dylibs are inside the Resources folder inside the framework bundle. I've used install_name_tool to update all the paths to:


Now, all the dylibs load correctly when used by an application but the command line tools when run fail with dyld: Library not loaded when run as follows:

// dylibpath is an NSString set the the path of the Resources folder within the framework

[task setEnvironment:[NSDictionary dictionaryWithObjectsAndKeys:@"DYLD_LIBRARY_PATH", dylibPath, nil]];
[task setLaunchPath:binConvert];
[task launch];
[task waitUntilExit];

Now, I come from a Windows background where the loader would find the DLLs if they reside in the same folder as the app but obviously OSX looks for a complete path. How can I get the command line tool to find the dylibs in the same folder?

Thanks, J

share|improve this question

1 Answer 1

up vote 2 down vote accepted

There are two things I can think of to try.

Option one

Using @rpath might be better suited for what you're trying to do. What's happening here is this:

Your libraries all expect that they will be positioned the same relative to whatever executable. They're all going to be at:


Which you could make work as long as you put all your libraries in the right place relative to the executables. Instead, you can set the install name on the dylibs (via install_name_tool) to @rpath/lib.dylib. This should then work with the DYLD_LIBRARY_PATH environment variable, but it's really suited for use with the -rpath compiler flag, so this may work, but I've never tried it.

Option two

You can also create symbolic links so that the library will actually be found by traversing from the executables to through the path you've set as the install name.

share|improve this answer
Thanks for your input, I think the symbolic link method is going to be the way to go with this. One last thing I'm not sure about - if I'm updating the path of the linked libraries to use a symbolic link in the same directory as the calling library what should I set the dylib 'id' to? I'm still unsure what the ID is used for, I believe it is the install path? –  JWood Feb 3 '11 at 20:42
I suppose what I should be asking is is there a @blah_path which will resolve to the framework root? I've created some symbolic links and linked the dylibs against them but I still have the issue where the paths are at different levels so when a dylib attempts to load another dylib there are too many '../' in the path and it fails again. –  JWood Feb 3 '11 at 21:20
You could try an install name of @rpath/libs/lib.dylib for everything. Any library/executable that uses the libraries would just need a symlink in the same dir that linked to the directory containing all the libraries. –  wbyoung Feb 3 '11 at 21:33
In the end I created a symlink to the libs folder in the same path as the calling executable and used @loader_path/libs/lib.dylib for everything and it works! Thanks for your help! –  JWood Feb 3 '11 at 23:00

Your Answer


