在需要时配置 Xcode 4 工作区以构建依赖项的正确方法是什么? [英] What's the correct way to configure Xcode 4 workspaces to build dependencies when needed?

查看:15
本文介绍了在需要时配置 Xcode 4 工作区以构建依赖项的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的案例很简单,一个有两个兄弟项目的工作区:一个主 (iOS) 应用程序和一个构建应用程序使用的多个静态库目标的项目.

My case is simple, a workspace with two sibling projects: one main (iOS) app and a project that builds several static library targets used by the app.

这是我配置构建的方式:

Here's how I have configured the build:

  • 将主应用构建设置中的用户标头搜索路径"指向库项目位置(通过源树)
  • 在我的应用程序的主要目标编辑器 -> 构建阶段 ->将二进制文件与库链接"部分,添加了我想要使用的库产品.
  • 在方案中,勾选查找隐式依赖关系"

在清理(并删除派生数据)后,在构建主项目期间,构建使我出现此错误:

After a clean (and deletion of the derived data), a build nets me this error during the build of the main project:

ld: library not found for -lChipmunk
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1

果然,如果我查看新创建的派生数据,可以找到的唯一目标文件是主应用程序,而不是库.对 *.o 文件的广泛发现"并未揭示任何相关内容,因此库不会丢失,它们肯定不会被构建.

Sure enough, if I look in the newly-created derived data, the only object files to be found are for the main app, not the libraries. A widespread 'find' for *.o files doesn't reveal anything relevant, so the libraries aren't getting lost, they're definitely not being built.

补充几点:

  • 当我在 Apple 开发论坛上询问此问题时,有人建议我应该在主要目标的构建阶段-> 目标依赖项编辑器中添加显式 deps.但是这里只能在相同项目或子项目中的targets中添加deps;就我而言,我将应用程序和图书馆项目作为工作场所的兄弟姐妹.
  • 如果我在主构建之前手动构建每个库,一切都很好.
  • when I've asked about this on the Apple dev forums, it's been suggested that I should add explicit deps in the main target's Build Phases->Target Dependencies editor. But you can only add deps here to targets in the same project or subprojects; in my case I have the app and library projects as workplace siblings.
  • if I build each library manually before the main build, all is fine.

我刚刚想出了一个解决方法,即将所有 deps 的目标添加到主应用程序方案的构建"部分.我之前尝试过但没有成功,但没有意识到我可以在列表中拖动目标以获得正确的构建顺序.构建现在以正确的顺序发生,无论是在清理之后,还是在库或主应用程序源中的更改之后.

I've just figured out a workaround, which is to add all the deps' targets into the 'build' part of the main app's scheme. I had tried this before without success, but hadn't realised that I could drag the targets around in the list to get the right build order. Builds now happen in the correct order, both after a clean, and after changes in either library or main app source.

我将问题留在这里,因为手动整理构建顺序肯定没有必要.我的设置方式肯定有问题.

I'm leaving the question here, because manually sorting out a build order surely shouldn't be necessary. There has to be something wrong with how I have things set up.

推荐答案

编辑方案(交换构建目标,取消/选中并行构建"和/或查找隐式依赖项")对我不起作用.在静态库中的任何代码更改之后,我仍然必须清理构建项目.搜索开发论坛,我终于找到了这个答案,这很神奇.

Editing the scheme (swapping around build targets, un-/check "Parallelize Build" and/or "Find Implicit Dependencies") didn't work for me. I still had to clean build the project, after any code change in the static lib. Searching the dev forums, I finally found this answer, which worked wonders.

确保标识和类型检查器正在显示并选择应用程序项目(而不是库)中的 libWhatever.a 文件.如果您看到位置:相对于项目 [或相对于组],这是您的问题.

Make sure the Identity and Type inspector is showing and select the libWhatever.a file in your application's project (not the library). If you see Location: Relative to Project [or Relative to Group], this is your problem.

  1. 单击相对于项目并将其更改为相对于构建产品.
  2. 这会改变链接的类型,但它仍然会被打破.
  3. 单击定位按钮并找到输出文件.

通过 Build Phases -> Link Binary with Libraries 将静态库添加到现有项目中,自动使其相对于组"(如果两者是同一个项目中的兄弟)工作区).以上述方式更改其位置可解决构建依赖性问题,并且在项目导航器中,您的 .a 文件应显示为黑色字母(而不是红色).

Adding a static lib to an existing project via Build Phases -> Link Binary with Libraries automatically makes it "Relative to Group" (if both are siblings in the same workspace). Changing its location the way described above resolves the build dependency problem and in the project navigator your .a file should appear in black letters (instead of red).

这篇关于在需要时配置 Xcode 4 工作区以构建依赖项的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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