我应该如何管理 Xcode 工作区中跨项目的依赖项? [英] How should I manage dependencies across projects in an Xcode workspace?

查看:34
本文介绍了我应该如何管理 Xcode 工作区中跨项目的依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个 iOS 应用程序项目,并将 json-framework 项目添加到工作区.左侧的项目导航器显示两个项目,构建方案选择器也显示两个项目的方案.现在我想将 json-framework 项目中的 libjson.a 目标添加为另一个项目中 iOS 应用程序目标的依赖项.预期的结果是,无论何时构建 app 目标,它都会构建(如有必要)库目标并将 app 目标链接到它.以下是我尝试过的方法:

I'm working on an iOS app project, and add the json-framework project to the workspace. The project navigator on the left shows both projects, and the build scheme selector shows the schemes from both projects too. Now I want to add the libjson.a target from the json-framework project as a dependency on the iOS app target in the other project. The expected result is that whenever the app target is built, it builds (if necessary) the library target and links the app target against it. Here are the ways I've tried to do this:

  • 将两者构建为同一方案的一部分.我尝试这样做的方法是为我的应用程序编辑方案,将 'libjson.a' 添加到方案的 'Build' 部分,顺便检查查找隐式依赖项".然后我转到我的应用程序目标的目标编辑器,在构建阶段"->链接二进制库"中,我从工作区库列表中选择libjson.a".当我随后尝试构建该方案时,我看到它构建了库目标,但构建应用程序目标失败,并出现链接器错误未找到 -ljson 的库"——这表明它实际上并未发现库已构建.确实在项目导航器中,库的应用项目下的条目仍然是红色的,表示该文件不存在.

  • Build both as part of the same scheme. The way I try this is to edit the scheme for my app, adding 'libjson.a' to the 'Build' portion of the scheme, and by the way "Find Implicit Dependencies" is checked. Then I go to the target editor for my app target, and in "Build Phases"->"Link Binary With Libraries", I choose 'libjson.a' from the list of workspace libraries. When I subsequently try to build the scheme, I see it build the library target, but building the app target fails with linker error "Library not found for -ljson" - suggesting that it hasn't actually discovered that the library has been built. Indeed in the project navigator, the entry under the app project for the library is still red indicating that the file doesn't exist.

将 json 目标添加为显式依赖项.为了尝试这个,我不修改构建方案,而是转到我的应用程序目标的目标编辑器,然后单击目标依赖项"下的添加按钮.没有来自工作区中其他项目的目标显示,因此这是一个非启动项.

Add the json target as an explicit dependency. To try this, I don't modify the build scheme, but go to the target editor for my app target and click the add button under 'Target Dependencies'. No targets from other projects in the workspace show up, so this is a non-starter.

将 JSON 项目拖到另一个项目中,然后将目标添加为依赖项.这就是我在 Xcode 3 中所做的.在项目导航器中,我抓取库项目并将其拖到应用程序项目上.这会显示通常的添加文件"窗格,我只需单击完成"即可将其关闭.项目导航器中的库项目现在有两个条目:一个在顶层,一个在应用程序项目下.我现在可以使用目标编辑器将库目标添加为应用程序目标的依赖项,并且可以在链接库阶段无误地链接它.但它看起来坏了:导航器中有同一个项目的多个条目.有没有其他方法可以做到这一点?

Drag the JSON project into the other project, then add the target as a dependency. This is what I would have done in Xcode 3. In the project navigator, I grab the library project and drag it over the app project. This brings up the usual 'add files' pane, which I just dismiss by clicking 'Finish'. There are now two entries for the library project in the project navigator: one at the top level, and one under the app project. I can now add the library target as a dependency of the app target using the target editor, and can link against it without error in the link libraries phase. But it looks broken: there are multiple entries for the same project in the navigator. Is there a different way to do this?

在同一工作区的不同项目中连接这些目标的Xcode 4-ish"方式应该是什么?如果同一工作区中的多个项目实际上不能相互交互,这似乎是缺乏的.谢谢,格雷厄姆.

What should be considered the "Xcode 4-ish" way of connecting these targets in different projects in the same workspace? It would seem lacking if multiple projects in the same workspace can't actually interact with each other. Thanks, Graham.

推荐答案

我刚刚设置了一个测试项目,就像你在版本 3 中描述的那样,通过创建一个新的工作区并将两个 Xcode 项目拖入其中,如图所示嵌套.

I’ve just set a test project up, pretty much as you describe in version 3, by creating a new workspace and dragging the two Xcode project into it, nested as shown.

如果您已经拥有同级项目,您可以删除它.

You can delete the sibling project if you have it already.

在此基础上进行构建,就我所见,它确实有效.

Hitting build on this and it just works, as far as I can see.

我想如果你有两个项目,内部路径会混乱,我倾向于在视图"->实用程序"->文件检查器"中摆弄位置设置,看看有什么效果.

I imagine there is internal path-confusion if you have two projects, and I’d be inclined to fiddle with location settings in "View"->"Utilities"->"File Inspector" and see what effect that has.

要尝试的另一件事是在 Xcode首选项..."->源树"中设置路径并以这种方式引用它们,如下所述:跨 iPhone 应用程序轻松、模块化的代码共享:静态库和跨项目引用

Another thing to try is to set your paths up in Xcode "Preferences…"->"Source Trees" and refer to them that way, as described here: Easy, Modular Code Sharing Across iPhone Apps: Static Libraries and Cross-Project References

HTH.安迪·W.

这篇关于我应该如何管理 Xcode 工作区中跨项目的依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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