带有 OpenCV 动态框架的 Swift 框架,未加载库 [英] Swift Framework with OpenCV Dynamic Framework, Library not loaded

查看:61
本文介绍了带有 OpenCV 动态框架的 Swift 框架,未加载库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个使用 OpenCV 的 iOS Swift 框架.出于良好实践,我们不想将 OpenCV 编译到我们的最终框架中,因为这可能会导致框架用户发生冲突和问题.

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.

我们发现我们正在下载/使用的 opencv2.framework 是一个静态库,因此我们研究了如何从源代码 (https://github.com/opencv/opencv/tree/3.4)

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)

我们用来将 OpenCV 构建为动态框架的源.

The sources we used to build OpenCV as a Dynamic framework.

https://docs.opencv.org/3.4.3/d5/da3/tutorial_ios_install.htmlhttps://github.com/opencv/opencv/pull/8009

简而言之,我们运行以下python脚本来构建动态框架

In short we ran the following python script to build the dynamic framework

python platforms/ios/build_framework.py ios --dynamic

我们成功地将 OpenCV 构建为动态框架,我们从 opencv/iOS/opencv2.framework 中获取了 opencv2.framework,因为这是模拟器和设备的通用框架.然后将其添加到我们的框架中.然后我们构建了我们的框架,并再次成功构建.

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

如果我们也将 opencv2.framework 添加到应用程序中,则会出现以下错误,这与上面的错误类似,只是参考不同:

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

这就是我的错误所在,为什么构建过程试图在 OpenCV 构建目录中查找框架?当opencv2.framework 被添加/嵌入到App 中时?

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.

旁注:您确定您创建 OpenCV 动态框架的解决方案适合您的最终用户吗?您正在强迫您的最终用户将 OpenCV 依赖项添加到他们的应用程序中 - 他们必须这样做才能使您的框架正常运行.

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.

但是,如果 OpenCV 仅作为静态库正式发布,这意味着您的客户会将其作为静态库添加到他们的项目中.我不确定正在寻找动态链接的 OpenCV 的框架是否能够使用静态链接的 OpenCV 库.不过很高兴被证明是错误的.

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.

这篇关于带有 OpenCV 动态框架的 Swift 框架,未加载库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆