I am having trouble getting a my XCode 4.2 project to run against a dynamic library (dynlib).
What I am doing is adding the library into xcode project, and then creating a new ‘Copy Files’ build phase with this lib.
The project does(!) run well if I set the Destination in the build phase to ‘Products Directory’, but then I have to deliver the lib with the app as opposed to embedded inside it.
I get the error in the title in all other settings of Destination in the build phase.
Also, I tried to quit xcode, delete build directory, clean, and all such tricks.
Is there a project/target setting I am missing?
Why is XCode looking for the dynlib in ‘../lib/’? (as shown in error)
You have two options a) change the library ID, b) change the final product.
The ID is embedded in the dylib and it defines where dyld will look for it. The ID is taken from the library at link time (when no other special flags are used). You can check it with
otool -L, e.g.:The first line is the ID of the dylib. You can change it using
install_name_tool -id <path> <library>. One option you have is to use the special form@executable_path/...which looks starting from the location of your binary (there are others as well).The second option (achieving the same thing) is to change the path to the library in your product. You can check how it links libraries with the same
otool -Lcommand:You can then change the libraries with
install_name_tool -change <old> <new> <target>, e.g.:Finally, note that Xcode usually does all this for you automatically if you let it manage the dylib (instead of copying it manually).