Im current working on creating a iOS Swift Framework that uses OpenCV. For good practice we don't want to compile OpenCV into our end framework as this can cause collisions and issues for the framework user.
We figured out that the opencv2.framework we were downloading/using was a static library, so we worked out how to create a dynamic version of the OpenCV Framework from source (https://github.com/opencv/opencv/tree/3.4)
The sources we used to build OpenCV as a Dynamic framework.
https://docs.opencv.org/3.4.3/d5/da3/tutorial_ios_install.html https://github.com/opencv/opencv/pull/8009
In short we ran the following python script to build the dynamic framework
python platforms/ios/build_framework.py ios --dynamic
We successfully built OpenCV as a Dynamic framework, we took the opencv2.framework from opencv/iOS/opencv2.framework as this is the universal framework for the simulator and the device. Then added it to our framework. Then we built our framework which again built successfully.
Then we added our framework to the embedded test application, and pressed run and we get the following error:
dyld: Library not loaded:
/Desktop/Workspace/OpenCV/ios/build/build-iphoneos/lib/Release/opencv2.framework/opencv2
Referenced from:
/private/var/containers/Bundle/Application/UUID/Test.app/Frameworks/SomeFramework.framework/SomeFramework
Reason: image not found
If we also add the opencv2.framework to the app, it gives the following error, this is similar to the error above just a different reference:
dyld: Library not loaded:
/Desktop/Workspace/OpenCV/ios/build/build-iphoneos/lib/Debug/opencv2.framework/opencv2
Referenced from:
/var/containers/Bundle/Application/UUID/TestApp.app/TestApp
Reason: image not found
This is where my error lies, why is the build process trying to find a framework within the OpenCV build directory? When the opencv2.framework is added/embedded within the App?
You might just need to add the frameworks to the Embedded Binaries of the app. See this answer.
Sidenote: are you sure your solution of creating an OpenCV dynamic framework is going to work out for your end users? You are forcing your end users to add the OpenCV dependency to their app - they will have to in order for your framework to function.
BUT, if OpenCV is only distributed officially as a static library, that means your customers will be adding it to their project as a static lib. I'm not sure if your framework, which is looking for a dynamically linked OpenCV, will be able to use the statically linked OpenCV library. Happy to be proven wrong about this though.
来源:https://stackoverflow.com/questions/57559389/swift-framework-with-opencv-dynamic-framework-library-not-loaded