将框架与 XCode 中的应用程序捆绑在一起 [英] Bundle framework with application in XCode

查看:18
本文介绍了将框架与 XCode 中的应用程序捆绑在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 XCode 新手.我正在尝试遵循 这些说明.显然我遗漏了一些东西,因为虽然我可以看到我想要的框架已被复制到应用程序包中,但我无法引用它.

I am an XCode novice. I am trying to follow these instructions. Clearly I am missing something because while I can see that the framework I want has been copied into the app bundle, I can't reference it.

当我从我以外的机器启动应用程序时(或者如果我从/Library/Frameworks/中删除 OpenCV),我收到以下错误:

When I start the application from a machine other than mine (or if I remove OpenCV from /Library/Frameworks/ ) I get the following error:

Dyld 错误消息:库不是加载:/Users/david/Library/Frameworks/OpenCV.framework/Versions/A/OpenCV参考自:/Users/g/Demo/Slates/ClipSplitter/build/Release/ClipSplitter.app/Contents/MacOS/ClipSplitter原因:找不到图片

Dyld Error Message: Library not loaded: /Users/david/Library/Frameworks/OpenCV.framework/Versions/A/OpenCV Referenced from: /Users/g/Demo/Slates/ClipSplitter/build/Release/ClipSplitter.app/Contents/MacOS/ClipSplitter Reason: image not found

如果这有什么不同的话,我的系统上没有用户david".这也是从 Internet 下载的预构建 OpenCV.(这是该项目的屏幕截图,根据评论中的要求.)

There is no user "david" on my system if that makes any difference. Also this is a prebuilt OpenCV downloaded from the internet. (Here’s a screenshot of the project as requested in comments.)

推荐答案

构建 OpenCV.framework 后,它已被配置为使用 /Users/david/Library/Frameworks/.

When the OpenCV.framework has been build it has been configured to use an install path of /Users/david/Library/Frameworks/.

由于您想将该库用作私有框架(安装在 ClipSplitter.app/Contents/Frameworks/OpenCV.framework 的应用程序包装器中),因此您必须更改其安装路径.这可以使用终端轻松完成,如下所示:

Since you want to use the library as a private framework (installed in the application wrapper at ClipSplitter.app/Contents/Frameworks/OpenCV.framework) you have to change its install path. This can be done easily using the terminal as follows:

$ install_name_tool -id @executable_path/../Frameworks/OpenCV.framework/OpenCV <your_path>/OpenCV.framework/OpenCV

当然要调整最后一个参数的路径.

Of course you have to adjust the path of the last argument.

现在,当链接您的应用程序时,您修改后的框架会告诉链接器 dyld 必须在您的应用程序的应用程序包装器中搜索 OpenCV.framework(在 ClipSplitter.app/Contents/Frameworks 目录中).

Now, when linking your application, your modified framework tells the linker that dyld has to search for the OpenCV.framework in the app wrapper of your application (in the ClipSplitter.app/Contents/Frameworks directory).

现在您必须将 OpenCV.framework 复制到您的应用程序包装器中.您可以通过添加复制文件构建阶段将其作为构建过程的一部分:右键单击您的目标,选择添加->新构建阶段->新复制文件构建阶段.从弹出的Destination"中选择Frameworks"并关闭对话框.

Now you have to copy the OpenCV.framework to your application wrapper. You can do this as part of your build process by adding a copy files build phase: Right-click on your target, select Add->New Build Phase->New Copy Files Build Phase. Select "Frameworks" from the "Destination" pop up and close the dialog.

您的目标现在将包含一个新阶段,您可以通过从 Xcode 窗口左侧的 Project Navigator 中拖动图标来添加 OpenCV.framework.请注意,Xcode 不允许您使用+"按钮将文件夹添加到 Copy Files 阶段,因此为了复制框架,您必须拖放它.

Your target will now contain a new phase to which you can add the OpenCV.framework by dragging the icon from the Project Navigator on the left side of Xcode window. Note that Xcode won't allow you to add a folder to the Copy Files phase by using the '+' button so in order to copy the framework you'll have to drag&drop it.

这篇关于将框架与 XCode 中的应用程序捆绑在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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