Some errors like this:
dyld: Library not loaded: /usr/local/lib/libXXX.dylib Referenced from: /sers/david/Projekte/Test/build/Debug/Test.app/Contents/MacOS/Test Reason: image not found
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”
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 the link : http://www.chilkatforum.com/questions/4235/how-to-distribute-a-dylib-with-a-mac-os-x-application
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.
In fact, there are 8 steps to deal with this issue:
1. Drag your custom dylib file to project
2. Click “+” at top of “Build Phases” page to add a “Copy Files” segment
3. Select “Framework” at destination line
4. Click “+” at the bottom of copy files segment to add your dylib
5. Click “+” at top of “Build Phases” page to add a “Run Script” segment
6. Past bellow line in shell box:
install_name_tool -id @executable_path/../Frameworks/libraryName.dylib “$SRCROOT/libraryName.dylib”
7. Change “libraryName.dylib” to your library name
Good luck! :)