How to define a library runtime location in Xcode4?-Collection of common programming errors

In my Cocoa application I’m using a third party C-library that is compiled in command line and available in a custom location.

In my Xcode project I can define where the library’s header files are located and where the library is looked during linking:

Header files location (HEADER_SEARCH_PATHS):

Target > Build Settings > Search Paths > Header Search Paths

Library location during linking (LIBRARY_SEARCH_PATHS):

Target > Build Settings > Search Paths > Library Search Paths

But how do I define the library’s runtime location ? At the moment when I run my Cocoa application in Xcode (cmd-r) I get an error from dynamic linker:

dyld: Library not loaded: /usr/local/lib/libfoo.1.dylib
  Reason: image not found

My application runs without problems when I create directory /usr/local/lib and a symbolic link to the library.

man dydl tells about three related environment variables:

  • DYLD_LIBRARY_PATH
  • DYLD_FALLBACK_FRAMEWORK_PATH
  • DYLD_FALLBACK_LIBRARY_PATH

I know how to set the variables on a bash terminal (see e.g. Where do I set DYLD_LIBRARY_PATH on Mac OS X, and is it a good idea?), but how do I set environment variables for Xcode ?

I’m running OS X 10.8.x and Xcode 4.5.x.