15

Thats my error:

dyld: Library not loaded: /usr/local/lib/libofa.0.dylib
Referenced from: /sers/david/Projekte/Test/build/Debug/Test.app/Contents/MacOS/Test
Reason: image not found

I've done some research and changed the path inside the dylib with install_name_tool:

davids-macbook:Test david$ otool -L libofa.0.0.0.dylib 
libofa.0.0.0.dylib:
@executable_path/../Frameworks/libofa.0.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)

But Xcode keeps searching for it in /usr/lib/:

build/Debug/Test.app/Contents/MacOS/Test:
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0)
/System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 1.0.0)
/opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
@executable_path/../Frameworks/TagLib.framework/Versions/A/TagLib (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0)
/opt/local/lib/libexpat.1.dylib (compatibility version 7.0.0, current version 7.2.0)
/System/Library/Frameworks/Quartz.framework/Versions/A/Quartz (compatibility version 1.0.0, current version 1.0.0)
/opt/local/lib/libcurl.4.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/local/lib/libofa.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 103.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 44.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.29.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.29.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.32.0)

Is there a way to set this in Xcode??? Thanks

Edit: The library is not a Xcode project. Its build with ./configure; make

david
  • 3,553
  • 4
  • 28
  • 39

3 Answers3

24

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.

mipadi
  • 398,885
  • 90
  • 523
  • 479
  • This doesn't seem to work. Still my error persists. I've set the the path with install_name_tool -id. I tried install-name_tool -add_rpath. nothing works. I tried setting the Runpath Search Paths and the Runtime Search Paths to @loader_path/../Frameworks Still its "dyld: Library not loaded: /usr/local/lib/libofa.0.dylib" – david Feb 04 '11 at 09:16
  • Stupid me. I had some stupid include settings in my project. Thanks! – david Feb 04 '11 at 09:56
  • 2
    Hi david, I have the same problem and cannot find out what you mean with 'stupid include settings'. Can you give a short example? – JackPearse Apr 04 '13 at 14:22
  • Same, also having this problem and NO solution on google has told me how to fix it – Geesu Sep 16 '13 at 02:08
  • how do you set the "Installation Directory of a library" using install_name_tool ? none of its options relates to "Installation Directory" ??? – Motti Shneor Jan 04 '16 at 08:26
  • 1
    @MottiShneor: It's the `-id` option. – mipadi Jan 04 '16 at 18:09
  • Oh. Thanks. now "id" stands for "Installation Directory" and not just... well... id? Fun with Apple. – Motti Shneor Jan 05 '16 at 19:55
  • @MottiShneor: No, it's short for "identification name", as noted in the man page. – mipadi Jan 05 '16 at 20:18
  • This fixed it! For the **pre-built** framework PGSQLKit in my OS X app, I had to add a build phase script `install_name_tool -id @executable_path/../Frameworks/PGSQLKit.framework/PGSQLKit "$SRCROOT/PGSQLKit.framework/PGSQLKit"` (substitute your framework's name accordingly). Also, note that I also had to remove runpath search paths other than `@executable_path/../Frameworks` before it finally worked. – Constantino Tsarouhas May 27 '16 at 21:56
8

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

Sven
  • 1,450
  • 3
  • 33
  • 58
itechnician
  • 1,645
  • 1
  • 14
  • 24
  • 1
    Great tip! By the way, for frameworks, use `install_name_tool -id @executable_path/../Frameworks/MyFramework.framework/MyFramework "$SRCROOT/MyFramework.framework/MyFramework"` (where `MyFramework` is the framework's name) instead. – Constantino Tsarouhas May 27 '16 at 22:01
4

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.

bikram990
  • 1,085
  • 1
  • 14
  • 36