views:

25

answers:

1

I have a Cocoa application as XCode project that has several supplementary bits of functionality as dylib targets.

When XCode builds the project, it places all the build outputs in a single folder: The .app bundle and the dylib files. And when executed from the XCode debugger, the .app launches.

I can't however launch the application from finder.

How do I setup XCode to 'deploy' the app in a standalone state? I have found that I can use ld on the actual app binary to contain a relative path to the dylibs: @executable_path/../../mylib.dylib

Running a script after each build seems wrong: there must be some way (that Im totally missing) to do this easily from inside XCode - it must be a common issue surely?


It looks like that XCode supports having @executable_path, @loader_path and @rpath used in the Target Info > Build > Linking > Dynamic Library Install Name setting (LD_DYLIB_INSTALL_NAME) setting.

The help text says: "Sets an internal "install path" (LC_ID_DYLIB) in a dynamic library. Any clients linked against the library will record that path as the way dyld should locate this library"

This seems very promising, but usability is a problem if I need to link dylibs in multiple paths against a common library - the relative path is going to be different each time.


Running my testapp from finder, I get the following (relevant) error text

Dyld Error Message:
  Library not loaded: @executable_path/../../util.dylib
  Referenced from: /Volumes/data/Code/TestApp/build/Debug/TestApp.app/Contents/MacOS/TestApp
  Reason: image not found

util.dylib is in /Volumes/data/Code/TestApp/build/Debug/ so I am confused :/

+1  A: 

You should use a Copy Files build phase to copy the dylib to the app's bundle when building the app. You'll want to copy it to Frameworks. You can then set the install path to @executable_path/../Frameworks/mylib.dylib.

mipadi
The project consists of multiple .app bundles, so the common dylibs have to go outside the .app bundle. Unless there is a cunning way to easily merge multiple executables into a single .app bundle that I also need to investigate :P
Chris Becke
You should copy the dylib into each app bundle. Or you can install it separately, in which case you should know where it's going to be (`/usr/local/lib` or whatever). Note that the apps won't run if they reference a dylib that's not included in their bundles or a common location on the user's file system.
mipadi