在 Xcode 4 中,你如何获得隐式依赖来处理工作区?

How do you get implicit dependencies to work with workspaces in Xcode 4?(在 Xcode 4 中,你如何获得隐式依赖来处理工作区?)

本文介绍了在 Xcode 4 中,你如何获得隐式依赖来处理工作区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Xcode 4 和 Cocoa Touch 静态库项目管理工作区中的项目,这些项目包含我可以从其他项目引用的共享代码.根据 WWDC 2010 视频和 Xcode 4 文档,Xcode 4 中的工作区有一个隐式依赖"功能.我一直在努力让它工作,但我没有取得太大的成功.

示例工作区:

  • 什么是正确的在需要时配置 XCode 4 工作区以构建依赖项的方法?
  • 似乎开发人员正在回退到旧技术,而不是真正使用新的隐式依赖"功能.

    如果我能帮助我理解如何在 Xcode 4 中使用隐式依赖项"来处理工作区,我将不胜感激.

    这是我的问题:

    • 隐式依赖项"应该如何在 Xcode 4 中与工作区一起工作?
    • 为什么在PrimaryApp中找不到Libary1和Library2中的代码?
    • 是否需要进行其他更改才能使依赖项在工作区中正常工作?

    解决方案

    我刚刚花了两天时间构建和重建我们的项目,就在这个问题上苦苦挣扎.虽然我现在有一个可以正确构建和链接的项目并且有工作的代码感知,但我对其中一个步骤并不 100% 满意,因为它似乎有点 hack 并且肯定不符合我的自动隐式依赖项"的概念.

    FWIW 这是我采取的步骤:

    1. 在 Xcode 中创建一个新的工作区.
    2. 为您的静态库添加一个新项目到工作区.您也可以添加现有项目,我发现这也可以.
    3. 测试库是否按预期构建.
    4. 为您的主项目添加一个新项目到工作区.我再次设法添加了一个现有的,但重要的是它没有任何已经链接到库的构建设置.如果您添加一个新项目,只需将现有源文件添加到其中就相当容易.我不想重组的非常大的预先存在的 SVN 存储库使我的特殊情况变得复杂.
    5. 在这个阶段,我将假设您的源代码已经包含从静态库中导入的标头.
    6. 在主项目的构建阶段,展开将二进制文件与库链接"部分并点击 + 符号.从您的静态库项目中选择目标.
    7. 如果您希望在此阶段进行,您可以构建主项目以确认其失败,如 OP 屏幕截图中所示,标题导入出现没有此类文件..."错误.
    8. 现在这是我不太喜欢的部分.在您的主项目中创建一个新组并将其命名为 Dependent Headers 或其他名称.现在在 project navigator 中,将任何使用的标题从您的静态项目拖到这个新组中.在弹出的选项中,我只是将其保留为默认设置.
    9. 您可能还需要将主项目与静态库使用的任何依赖库相关联.例如,我的静态库使用了 libxml2 和 CFNetwork,即使我的主项目没有直接使用它们,如果我没有将它们添加到使用库链接二进制文件"构建阶段,也会出现编译错误.
    10. 您的主要项目现在应该(希望)构建.

    我真的不喜欢第 8 步和第 9 步.这真的感觉 XCode 并没有像广告宣传的那样做.但是,如果它得到修复,至少这些步骤很容易退出,以便它正常工作.

    我认为隐式依赖"应该可以工作,而无需经过第 6 步,甚至可能是第 5 步,但对于很多人的口味来说,这可能有点太自动化了.

    I want to manage projects in workspaces using Xcode 4 with Cocoa Touch Static Library projects which contain shared code that I could reference from other projects. According to WWDC 2010 videos and the Xcode 4 documentation there is a feature for "implicit dependencies" for workspaces in Xcode 4. I have been trying to make it work and I am not having much success.

    Sample Workspace: DependenciesInXcode4.zip

    You can see the very basic sample project has 2 static library projects which I named Library1 and Library2. I then have a single class in each project which I reference from the iPhone project called PrimaryApp. I get support from Code Sense when adding the import statement but the build fails.

    You can see how the build fails because it cannot find the dependencies.

    To resolve these issues I added manually linked the Library1 and Library2 projects.

    I also had to add the path to these projects as Header Search Paths.

    Now when I build both of the dependency libraries and then run PrimaryApp in the iPhone Simulator it builds successfully and runs. I have found that it does not always ensure that the dependency projects are built when necessary and this is clearly a manual process. This is not what I consider "implicit dependencies" as the Xcode videos and documentation imply that it should work. I have been looking for more concrete examples but so far I have had no luck. Even here on Stackoverflow I do not see a satisfactory answer yet.

    • How should I manage dependencies across projects in an Xcode workspace?
    • What's the correct way to configure XCode 4 workspaces to build dependencies when needed?

    It appears that developers are falling back to old techniques and not truly using the new "implicit dependencies" features.

    I'd appreciate some help with understanding how to get "implicit dependencies" to work with workspaces in Xcode 4.

    Here are my questions:

    • How are "implicit dependencies" supposed to work in Xcode 4 with workspaces?
    • Why can't the code in Libary1 and Library2 be found automatically in PrimaryApp?
    • Are additional changes required to make dependencies work in a workspace?

    解决方案

    I have just spent the best part of two days building and rebuilding our project, struggling with just this very issue. Whilst I now have a project that builds and links correctly AND has working codesense I am not 100% happy with one of the steps as it seems to be a bit of a hack and certainly doesn't fit my concept of "Automatic implicit dependencies".

    FWIW here are the steps I took:

    1. Create a new Workspace in Xcode.
    2. Add a new project to the workspace for your static library. You can also add an existing project, I found this to work too.
    3. Test that the library builds as expected.
    4. Add a new project to the workspace for your main project. Again I managed to add an existing one, but importantly it did not have any build settings already that linked to the library. If you add a new project its fairly easy to just add existing source files to it. My particular situation was complicated by a very large pre-existing SVN repository that I did not want to restructure.
    5. At this stage I am going to assume that your source code already contains imports of headers from the static library.
    6. In the build phases for the main project, expand the "link binary with libraries" section and click the + symbol. Select the target from your static library project.
    7. If you want at this stage you can build the main project to confirm that it fails as shown in the OP screen shots with "No such file..." errors for the header imports.
    8. Now this is the bit I don't really like. In your main project create a new group and call it Dependent Headers or whatever. Now in the project navigator drag any used headers from your static project to this new group. In the options pop up I just left it as the default settings.
    9. You may also need to link your main project with any dependent libraries used by your static library. For example my static library makes use of libxml2 and CFNetwork and even though my main project does not use them directly I had compile errors if I did not add them to the "link binary with libraries" build phase.
    10. Your main project should now (hopefully) build.

    I really don't like steps 8 and 9. This really feels like XCode is not doing what it is advertised to do. However if and when it gets fixed at least these steps are fairly easy to back out so that it works correctly.

    I think "implicit dependencies" should work without needing to go past step 6, maybe even step 5 but that might be a little bit too automagical for a lot of people's taste.

    这篇关于在 Xcode 4 中,你如何获得隐式依赖来处理工作区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

    本文标题为:在 Xcode 4 中,你如何获得隐式依赖来处理工作区?

    基础教程推荐