安装自定义可可框架的最佳方法 [英] Best way to install a custom cocoa framework

查看:32
本文介绍了安装自定义可可框架的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义框架,遵循 Apple 框架编程指南中的建议 >> 安装你的框架 我安装在/Library/Frameworks 中.我通过使用以下脚本添加运行脚本构建阶段来做到这一点:

cp -R build/Debug/MyFramework.framework/Library/Frameworks

然后,在我的项目中,我链接到/Library/Frameworks/MyFramework 并将其导入我的类中,如下所示:

#import <MyFramework/MyFramework.h>

这很好用,只是我总是在调试器控制台中看到以下消息:

<块引用>

正在将程序加载到调试器中...共享库应用加载规则全部警告:无法读取/Users/elisevanlooij/Library/Frameworks/MyFramework.framework/Versions/A/MyFramework"的符号(未找到文件).警告:无法从MyFramework"中读取符号(尚未映射到内存中).程序已加载.

显然,编译器首先在/Users/elisevanlooij/Library/Frameworks 中查找,找不到 MyFramework,然后在/Library/Frameworks 中查找,确实找到了 MyFramework 并继续其愉快的方式.到目前为止,这更像是一个烦恼而不是真正的问题,但是在运行单元测试时,gdb 会在(找不到文件)上停止并拒绝继续.我已经通过在运行脚本阶段添加额外的行来解决问题

cp -R build/Debug/MyFramework.framework ~/Library/Frameworks

但感觉就像是在卖一开始就不应该破坏的东西.我该如何解决这个问题?

解决方案

在过去的几个月里,我学到了很多关于框架的知识,所以我正在重写这个答案.请注意,我说的是在开发工作流程中安装框架.

安装公共框架(即,将由多个应用程序或捆绑包使用的框架)的首选位置是/Library/Frameworks[link text],因为此位置的框架由编译器自动发现在编译时和运行时动态链接器."[框架编程指南].最优雅的方法是在构建设置的部署部分.

在构建框架时,有时您确实想在构建时更新框架,有时又不想.出于这个原因,我只在发布配置中更改部署设置.所以:

  1. 双击框架目标以打开目标信息窗口并切换到构建选项卡.
  2. 在配置"选择框中选择发布".
  3. 向下滚动到部署部分并输入以下值:

<块引用>

部署位置 = YES(单击复选框)

安装构建产品位置 =/

安装目录 =/Library/Frameworks

安装构建产品位置用作安装的根目录.它的默认值是某个/tmp 目录:如果你不将它更改为系统根目录,你将永远看不到你安装的框架,因为它隐藏在/tmp 中.

现在您可以在 Debug 配置中随意处理您的框架,而不会影响您的其他项目,当您准备好发布时,您所需要做的就是切换到 Release 并进行 Build.

Xcode 4 警告自从切换到 Xcode 4 后,我的自定义框架遇到了许多问题.大多数情况下,它们链接 GDB 中的警告,这些警告不会真正干扰框架的有用性,除非在运行内置单元测试时.一周前我已经向 Apple 提交了技术支持票,他们仍在调查中.当我得到一个可行的解决方案时,我会更新这个答案,因为这个问题已经证明很受欢迎(1 kViews 和计数).

I have a custom framework that, following the advice in Apple's Framework Programming Guide >> Installing your framework I install in /Library/Frameworks. I do this by adding a Run Script build phase with the following script:

cp -R  build/Debug/MyFramework.framework /Library/Frameworks

In my projects I then link against /Library/Frameworks/MyFramework and import it in my classes like so:

#import <MyFramework/MyFramework.h>

This works very well, except that I always see the following message in my debugger console:

Loading program into debugger… sharedlibrary apply-load-rules all warning: Unable to read symbols for "/Users/elisevanlooij/Library/Frameworks/MyFramework.framework/Versions/A/MyFramework" (file not found). warning: Unable to read symbols from "MyFramework" (not yet mapped into memory). Program loaded.

Apparently, the compiler first looks in /Users/elisevanlooij/Library/Frameworks, can't find MyFramework, then looks in /Library/Frameworks, does find MyFramework and continues on its merry way. So far this has been more of an annoyance than a real problem, but when runnning unit tests, gdb stops on the (file not found) and refuses to continue. I have solved the problem by adding an extra line to the Run Script Phase

cp -R  build/Debug/MyFramework.framework ~/Library/Frameworks

but it feels like sello-taping something that shouldn't be broken in the first place. How can I fix this?

解决方案

In the past months, I've learned a lot more about frameworks, so I'm rewriting this answer. Please note that I'm talking about installing a framework as part of the development workflow.

The preferred location for installing a public framework (i.e. a framework that will be used by more than one of your apps or bundles) is /Library/Frameworks[link text] because "frameworks in this location are discovered automatically by the compiler at compile time and the dynamic linker at runtime."[Framework Programming Guide]. The most elegant way to do this is in the Deployment section of the Build settings.

As you work on your framework, there are times when you do want to update the framework when you do a build, and times when you don't. For that reason, I change the Deployment settings only in the Release Configuration. So:

  1. Double-click on the framework target to bring up the Target info window and switch to the Build tab.
  2. Select Release in the Configuration selectbox.
  3. Scroll down to the Deployment section and enter the following values:

Deployment Location = YES (click the checkbox)

Installation Build Products Location = /

Installation Directory = /Library/Frameworks

The Installation Build Products Location serves as the root of the installation. Its default value is some /tmp directory: if you don't change it to the system root, you'll never see your installed framework since it's hiding in the /tmp.

Now you can work on your framework as you like in the Debug configuration without upsetting your other projects and when you are ready to publish all you need to do is switch to Release and do a Build.

Xcode 4 Warning Since switching to Xcode 4, I've experienced a number of problems with my custom framework. Mostly, they are linking warnings in GDB that do not really interfere with the usefulness of the framework, except when running the built-in unit-test. I have submitted a technical support ticket to Apple a week ago, and they are still looking into it. When I get a working solution I will update this answer since the question has proven quite popular (1 kViews and counting).

这篇关于安装自定义可可框架的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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