Legoless / OpenCV-Dynamic

OpenCV iOS Dynamic Framework Podspec
http://opencv.org
Other
24 stars 13 forks source link

"dyld: Library not loaded" error #11

Closed alwc closed 5 years ago

alwc commented 5 years ago

I've tried pod install with the following Podfile,

platform :ios, '12.0'

target 'OpenCVproject' do
  use_frameworks!
  pod 'OpenCV-Dynamic', '~> 4.0'
end

but I'm getting the following error in Xcode when I'm try to run it on a simulator

dyld: Library not loaded: /Users/alwc/Library/Caches/CocoaPods/Pods/Release/OpenCV-Dynamic/4.0.1-bbf99/ios/build/build-iphoneos/lib/Release/opencv2.framework/opencv2
  Referenced from: /var/containers/Bundle/Application/FC552AA2-93FE-4C46-92C4-72E42EE4E0A8/OpenCVproject3.app/OpenCVproject3
  Reason: image not found

When I look at /Users/alwc/Library/Caches/CocoaPods/Pods/Release/OpenCV-Dynamic/4.0.1-bbf99/, I realize there are only

LICENSE           README.md         opencv            opencv2.framework      

So the loaded path is incorrect.

If I manually create /ios/build/build-iphoneos/lib/Release/opencv2.framework/opencv2 in 4.0.1-bbf99, then it works in simulator. If I build and run this on my iPhone X, I'll still get the same dyld: Library not loaded: error despite the fact that I manually created the path in 4.0.1-bbf99. How can I fix this?

JakeWade3 commented 5 years ago

Getting the same issue! Any ideas on how to solve this

AngryDuckFTW commented 5 years ago

+1

alwc commented 5 years ago

@JakeWade3 @AngryDuckFTW It has been a while since I fixed the problem, but here are the instructions to fix it.

  1. Go to the directory that locates opencv2.framework
  2. If you type otool -L opencv2.framework/opencv2 in your terminal, you should get something like this
$ otool -L opencv2.framework/opencv2

opencv2.framework/opencv2:
        /Users/alwc/projects/opencv/ios_arm64_dynamic_test/build/build-arm64-iphoneos/lib/Release/opencv2.framework/opencv2 (compatibility version 4.1.0, current version 4.1.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)

Note that the opencv2.framework/opencv2's parent (i.e. first file path) is a fixed path on your computer.

  1. Now type install_name_tool -id "@rpath/opencv2.framework/opencv2" opencv2.framework/opencv2 in your terminal and you'll see the opencv2.framework/opencv2's parent has become @rpath:
$ otool -L opencv2.framework/opencv2 

opencv2.framework/opencv2:
        @rpath/opencv2.framework/opencv2 (compatibility version 4.1.0, current version 4.1.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)

These 3 steps should be able to solve your dynamic build problem.