10

I'm still quite new to Objective C and Xcode, but I just finished a small app that uses the openCV libopencv_core.2.4.2.dylib.

When I went to open the final built app on another machine, OS X threw me this error:

Dyld Error Message:   Library not loaded: */libopencv_core.2.4.dylib  
Referenced from: /Users/USER/Desktop/my
app.app/Contents/MacOS/my app   
Reason: image not found

Why is my app looking for 2.4 instead of 2.4.2 here?

What I already checked:

I added a new build phase -> so that libopencv_core.2.4.2.dylib is copied to the app package (via "Copy Bundle Resources" in Xcode) - libopencv_core.2.4.2.dylib now lies in my app.app/Resources

What did I miss? Do I have so set some more library search paths or similar?

What I also did:

install_name_tool -id "@executable_path/../Frameworks/libopencv_core.2.4.2.dylib" libopencv_core.2.4.2.dylib

Copying the dylib to the Frameworks directory doesn't work either:

Library not loaded: @executable_path/../Frameworks/libopencv_core.2.4.2.dylib

Don't know what to do now - the dylib is in the Frameworks directory of my app...

Using otool -L on the binary gives me:

/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
    @loader_path/../Frameworks/libopencv_core.2.4.2.dylib (compatibility version 2.4.0, current version 2.4.2)
    @loader_path/../Frameworks/libopencv_highgui.2.4.2.dylib (compatibility version 2.4.0, current version 2.4.2)
    @loader_path/../Frameworks/libopencv_imgproc.2.4.2.dylib (compatibility version 2.4.0, current version 2.4.2)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.11.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.1.0)
    /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData (compatibility version 1.0.0, current version 407.7.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.33.0)
Nathan
  • 4,009
  • 2
  • 20
  • 21
kava
  • 193
  • 1
  • 2
  • 13
  • Did you check (using `otool -L`) that your use of `install_name_tool` actually changed the reference within your binary? – trojanfoe Nov 26 '12 at 12:19
  • it did yes. i consider using opencv as a private framework instead. i downloaded one - but it seems it won't compile for x86_64 ? – kava Nov 26 '12 at 15:33
  • Just to clarify, are you running `install_name_tool` on your **binary** (not the `.dylib`)? – trojanfoe Nov 26 '12 at 15:36
  • I opened the .app package and ran it on the .dylib inside the .app. Still I'm not sure if this is the right way to distribute an app with openCV. – kava Nov 26 '12 at 15:55
  • What about the binary? Try an `otool -L` on that... – trojanfoe Nov 26 '12 at 16:12
  • it gives me: @executable_path/../Frameworks/libopencv_core.2.4.dylib (which sounds fine now) But It's strange because I always used **libopencv_core.2.4.2.dylib** Why is my app suddenly searching for another version of the dylib? – kava Dec 02 '12 at 20:12
  • See if this helps: http://stackoverflow.com/a/7170560/76810 – SSteve Dec 12 '12 at 01:03
  • Yes that helped - Thats a good way. Thanks. I now have it all running - but I also tried a different way - compiling the dylibs with the @path in them in Xcode. thats solved everything. – kava Dec 16 '12 at 10:43

3 Answers3

2

I had the same problem. i keep all .dylib in system root directory usr/lib it working fine. At the run time .o file not get .dylib file path then it gives an error.

kunalg
  • 1,570
  • 1
  • 12
  • 18
1

I found a better solution: recompiling openCV in Xcode and set the @executable_path/../Frameworks in the build settings, for every .dylib you compile - now the .dylibs themselves always "know where they are".

kava
  • 193
  • 1
  • 2
  • 13
0

Since other answers are not clear enough;

Assume your dylib files are located in /usr/local/opt/opencv3/lib

sudo ln -s /usr/local/opt/opencv3/lib/*.dylib /usr/local/lib

will solve this problem. Be aware that /usr/lib is protected by system in MacOS, thus you should use /usr/local/lib.

Halil
  • 2,076
  • 1
  • 22
  • 30