dyld: Library not loaded: /Users/cntp/Documents/opencv-4.1.0/platforms/ios/ios/build/build-iphonesimulator/lib/Release/opencv2.framework/opencv2
Referenced from: /private/var/containers/Bundle/Application/UUID/MyApp.app/Frameworks/MyApp.framework/MyApp Reason: image not found
使用otool工具查看,会发现二进制文件中将链接路径写成固定路径:
cntp@TPL-0000-161520deMacBook-Pro opencv2.framework % otool -L opencv2 opencv2: /Users/cntp/Documents/opencv-4.1.0/platforms/ios/ios/build/build-iphonesimulator/lib/Release/opencv2.framework/opencv2 (compatibility version 4.1.0, current version 4.1.0)
CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice. The suite of CMake tools were created by Kitware in response to the need for a powerful, cross-platform build environment for open-source projects such as ITK and VTK.
第一步:查看是否安装Cmake
如果想在Mac上编译OpenCV,需要检测Mac中是否安装过Cmake。
对于如何查看,我们可以直接在终端输入cmake --version,如果有相应版本会出现下方内容:
1 2 3 4 5
cntp@TPL-0000-161520deMacBook-Pro ~ % Cmake --version cmake version 3.17.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
如果出现-bash: cmake: command not found则代表电脑中并没有安装Cmake。
cntp@TPL-0000-161520deMacBook-Pro opencv2.framework % otool -L opencv2 opencv2: /Users/cntp/Documents/opencv-4.1.0/platforms/ios/ios/build/build-iphonesimulator/lib/Release/opencv2.framework/opencv2 (compatibility version 4.1.0, current version 4.1.0) /System/Library/Frameworks/Accelerate.framework/Accelerate (compatibility version 1.0.0, current version 4.0.0) /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics (compatibility version 64.0.0, current version 1251.12.0) /System/Library/Frameworks/QuartzCore.framework/QuartzCore (compatibility version 1.2.0, current version 1.11.0) /System/Library/Frameworks/AssetsLibrary.framework/AssetsLibrary (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/UIKit.framework/UIKit (compatibility version 1.0.0, current version 61000.0.0) /System/Library/Frameworks/AVFoundation.framework/AVFoundation (compatibility version 1.0.0, current version 2.0.0) /System/Library/Frameworks/CoreImage.framework/CoreImage (compatibility version 1.0.0, current version 5.0.0) /System/Library/Frameworks/CoreMedia.framework/CoreMedia (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/CoreVideo.framework/CoreVideo (compatibility version 1.2.0, current version 1.5.0) /System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 1570.15.0) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.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.250.1) /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation (compatibility version 150.0.0, current version 1570.15.0) /usr/lib/libc++abi.dylib (compatibility version 1.0.0, current version 400.17.0)
cntp@TPL-0000-161520deMacBook-Pro opencv2.framework % install_name_tool h Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool [-change old new] ... [-rpath old new] ... [-add_rpath new] ... [-delete_rpath old] ... [-id name] input cntp@TPL-0000-161520deMacBook-Pro opencv2.framework % install_name_tool -id @rpath/opencv2.framework/opencv2 opencv2 cntp@TPL-0000-161520deMacBook-Pro opencv2.framework % otool -L opencv2 opencv2: @rpath/opencv2.framework/opencv2 (compatibility version 4.1.0, current version 4.1.0) /System/Library/Frameworks/Accelerate.framework/Accelerate (compatibility version 1.0.0, current version 4.0.0) /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics (compatibility version 64.0.0, current version 1251.12.0) /System/Library/Frameworks/QuartzCore.framework/QuartzCore (compatibility version 1.2.0, current version 1.11.0) /System/Library/Frameworks/AssetsLibrary.framework/AssetsLibrary (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/UIKit.framework/UIKit (compatibility version 1.0.0, current version 61000.0.0) /System/Library/Frameworks/AVFoundation.framework/AVFoundation (compatibility version 1.0.0, current version 2.0.0) /System/Library/Frameworks/CoreImage.framework/CoreImage (compatibility version 1.0.0, current version 5.0.0) /System/Library/Frameworks/CoreMedia.framework/CoreMedia (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/CoreVideo.framework/CoreVideo (compatibility version 1.2.0, current version 1.5.0) /System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 1570.15.0) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.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.250.1) /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation (compatibility version 150.0.0, current version 1570.15.0) /usr/lib/libc++abi.dylib (compatibility version 1.0.0, current version 400.17.0) cntp@TPL-0000-161520deMacBook-Pro opencv2.framework %
In computing, rpath designates the run-time search path hard-coded in an executable file or library. Dynamic linking loaders use the rpath to find required libraries.
Specifically, it encodes a path to shared libraries into the header of an executable (or another shared library). This RPATH header value (so named in the Executable and Linkable Format header standards) may either override or supplement the system default dynamic linking search paths.