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

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

问题描述

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

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:


  • 将两者构建为同一方案的一部分。我尝试的方法是为我的应用程序编辑方案,在方案的 Build部分中添加 libjson.a,并选中 Find Implicit Dependencies。然后,转到应用程序目标的目标编辑器,然后在构建阶段->使用库链接二进制文件中,从工作区库列表中选择 libjson.a。
    当我随后尝试构建该方案时,我看到它构建了库目标,但是构建应用程序目标失败,并显示链接器错误找不到-ljson的库-表示它实际上并未发现该库已建成。确实,在项目导航器中,库的app项目下的条目仍然为红色,指示文件不存在。

  • 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中要做的。在项目导航器中,我抓取了库项目并将其拖到应用程序项目上。这将弹出通常的添加文件窗格,我只需单击完成即可将其关闭。
现在,项目导航器中的库项目有两个条目:一个在顶层,一个在app项目下。现在,我可以使用目标编辑器将库目标添加为应用程序目标的依赖项,并且可以在链接库阶段对其进行链接而不会出错。但是它看起来很残破:导航器中的同一项目有多个条目。有其他方法可以做到这一点吗?

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 Preferences ...-> Source Trees中找到您的路径,并以这种方式进行引用,如下所述:跨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天全站免登陆