OSX framework linking issues

1.8k views Asked by At

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:

@executable_path/../Frameworks/MyCompany.framework/Versions/A/Resources/lib.dylib

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

NSTask *task = [[[NSTask alloc]init]autorelease];
[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

1

There are 1 answers

4
wbyoung On BEST ANSWER

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:

@executable_path/../Frameworks/MyCompany.framework/Versions/A/Resources/lib.dylib

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.