Xcode 4 adding dylib

The issue is not where Xcode is looking for the library at compile time, which is what Simon Whitaker's answer addresses.

The issue is that the application which uses the dylib cannot find it at runtime. When an application is built that uses a dynamic library, it copies the install_name of the dylib into the output binary.

Creating a copy files phase and copying the dylib to the Frameworks subdirectory of the app's bundle is the right thing do do.

However, you need to do an additional step. You need to compile the dynamic library with an install_name appropriate for a bundle app. By default, a dynamic library is created with an install_name of /usr/local/lib. The app can't find your library there because it doesn't exist. Even if you put the library there, your users certainly won't have it, so that would be the wrong solution.

The right solution is bundling the library with the app. To set the install name for the dynamic library, go into the dynamic library project and set the "Dynamic Library Install Name" option to: @executable_path/../Frameworks/libmydynamiclibrary.dylib


Xcode is looking in /usr/local/lib/ for the library. If the library is in another location, add that location to your Library Search Paths:

  1. Select project file in Xcode 4
  2. Select the target, then click the Build Settings tab
  3. Make sure All is selected in the filter bar (not Basic)
  4. Scroll down to the Search Paths section and you'll find Library Search Paths in there