Xcode keeps searching dylib at wrong path Xcode keeps searching dylib at wrong path xcode xcode

Xcode keeps searching dylib at wrong path


Normally what I do is this:

  1. Set the Installation Directory of the library to @rpath. This will set the install name to @rpath/libofa.0.0.0.dylib. If you're building the library yourself, you can set this in Xcode; otherwise, use install_name_tool to change it.
  2. Set the Runpath Search Paths of the application using the library to the location of the directory containing the library. For example, if you put the library in the app's Frameworks directory, you'd set Runpath Search Paths to @executable_path/../Frameworks (or @loader_path/../Frameworks).

This blog post and this one go into more detail.


Make sure to install the command line tools from developer.apple.com and then add the library in your project. Run the following script in your Xcode: Targets » Build Phases » Run Script and just execute:

install_name_tool -id @executable_path/../Frameworks/librayName.dylib "$SRCROOT/librayName.dylib"

Note: NO ' or "" required before dylib name


Before going for solution, you should know what is new with dependent library "dylib" in MAC as compare to dependent library "dll" in windows.

The major difference in dylib vs dll is "install name". The install name is a path baked into the dynamic library that says where to find the library at runtime. It does not matter where you copy your dylibs, It will always point to old path(except without changing install name).You can know original search path(install name) by using command as below

otool -L a.dylib

(just drag dylib in place of a.dylib)

For more detail about install name, refer this link.

Now, solution for changing the new location for dylib("install name") is just use install_name_tool as below

install_name_tool -change *old path of dylb* *new path of dylib*

you can get old path by otool -L command described above already.(old path i.e. original path)

install_name_tool -change can change search path of dylib and executable as well.

You can use this in Xcode by writing in Run script file in your project.