如何在Xcode 4中使用隐式依赖项来处理工作空间? [英] How do you get implicit dependencies to work with workspaces in Xcode 4?

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

问题描述

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



示例工作区:

  • 什么是正确的方法配置XCode 4工作区以在需要时构建依赖项?



  • 看来开发人员正在回归旧技术而不是真正使用新的隐式依赖功能。



    我很感激帮助理解如何在Xcode 4中使用隐式依赖来处理工作空间。



    以下是我的问题:




    • 隐式依赖关系应如何工作Xcode 4带工作区?

    • 为什么不能在PrimaryApp中自动找到Libary1和Library2中的代码?

    • 是否需要进行其他更改才能使依赖项在工作空间中运行?


    解决方案

    我刚刚花了两天的时间来构建和重建我们的项目,奋力拼搏正是这个问题。虽然我现在有一个正确构建和链接的项目并且具有工作代码,但我对其中一个步骤并不百分之百,因为它似乎有点像黑客,当然不符合我的自动隐式依赖概念。



    FWIW以下是我采取的步骤:


    1. 创建一个新的工作区Xcode中。

    2. 将新项目添加到静态库的工作区。你也可以添加一个现有项目,我发现它也可以工作。

    3. 测试库是否按预期构建。

    4. 添加一个新项目到主项目的工作区。我再次设法添加一个现有的,但重要的是它没有任何链接到库的构建设置。如果添加新项目,只需将现有源文件添加到其中即可。我的特殊情况由于一个非常大的预先存在的SVN存储库而变得复杂,我不想重构。

    5. 在这个阶段,我将假设您的源代码已经包含静态库中的头文件导入。

    6. 在构建阶段主项目,展开链接二进制文件库部分,然后单击+符号。从静态库项目中选择目标。

    7. 如果你想在这个阶段你可以构建主项目以确认它失败,如OP屏幕截图所示没有这样的文件。 ..标题导入的错误。

    8. 现在这是我不喜欢的。在您的主项目中创建一个新组并将其称为Dependent Headers或其他任何内容。现在,在项目导航器中,将所有已使用的标头从静态项目拖到此新组。在弹出的选项中,我将其保留为默认设置。

    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.

    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中使用隐式依赖项来处理工作空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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