将框架与 XCode 中的应用程序捆绑在一起

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1621451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:55:14  来源:igfitidea点击:

Bundle framework with application in XCode

xcodeframeworks

提问by Gareth Simpson

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.

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

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

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

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

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

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 projectas requested in comments.)

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

回答by Nikolai Ruhe

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

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

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:

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

$ 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.

当然你必须调整最后一个参数的路径。

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).

现在,当链接您的应用程序时,您修改后的框架会告诉链接器 dyld 必须在应用程序的应用程序包装器中搜索 OpenCV.framework(在 ClipSplitter.app/Contents/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.

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

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 窗口左侧的项目导航器中拖动图标来添加 OpenCV.framework。请注意,Xcode 不允许您使用“+”按钮将文件夹添加到“复制文件”阶段,因此为了复制框架,您必须拖放它。

回答by Gareth Simpson

You need to set the build setting "Installation directory" to @executable_path/../Frameworks

您需要将构建设置“安装目录”设置为 @executable_path/../Frameworks

See the chapter about Embedding a Private Framework in Your Application Bundle in https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html

请参阅https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html 中有关在应用程序包中嵌入私有框架的章节

Regards

问候

回答by james_womack

Using Xcode 5, you can facilitate this using the Build Phasespanel of your application target.

使用 Xcode 5,您可以使用Build Phases应用程序目标的面板来简化此操作。

The default appearance of this panel is

这个面板的默认外观是

By pressing the "+" button underneath Copy Files, you can add your framework as a file that will be copied into Frameworks in your app bundle.

通过按下Copy Files下方的“+”按钮,您可以将您的框架添加为一个文件,该文件将被复制到您的应用程序包中的框架中。

Now, when you build, your Framework(s) will be copied into your bundle.

现在,当您构建时,您的框架将被复制到您的包中。