xcode 同一工作区中两个项目之间的目标依赖关系

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10264440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:02:26  来源:igfitidea点击:

Target Dependency between two projects in the same workspace

xcodemacosbuildlinker

提问by jtbandes

I'm using Xcode 4.3 to create a framework for OS X. I created a workspace and a project (with a framework target) to go in this workspace.

我正在使用 Xcode 4.3 为 OS X 创建一个框架。我创建了一个工作区和一个项目(带有框架目标)以进入该工作区。

Now, I want to include & link with a third-party framework which I've also added to the same workspace(but not within my project). I clicked the +button in the "Link Binary With Libraries" build phase, and the third-party framework simply appeared in the list of available libraries.

现在,我想包含并链接到我也添加到同一个工作区(但不在我的项目中)的第三方框架。我+在“ Link Binary With Libraries”构建阶段点击了按钮,第三方框架直接出现在可用库列表中。

The linked framework shows up red in the Project navigator, as the third-party library has not been built yet (confusingly, though, my project successfully builds — although I'm not yet trying to usethe third-party framework):

链接的框架在项目导航器中显示为红色,因为尚未构建第三方库(但令人困惑的是,我的项目已成功构建——尽管我还没有尝试使用第三方框架):

I was going to solve this by adding it as a Target Dependency, but when I click +on the "Target Dependencies" build phase, the third-party target doesn't show up in the list.

我打算通过将其添加为目标依赖项来解决这个问题,但是当我单击+“目标依赖项”构建阶段时,第三方目标没有显示在列表中。

How should I properly configure/resolve this dependency?Also, do I need to create a Copy Files build phase to ensure the framework is copied into my target's Frameworks directory? How would I set that up properly?

我应该如何正确配置/解决这种依赖关系?另外,我是否需要创建一个 Copy Files 构建阶段以确保将框架复制到目标的 Frameworks 目录中?我该如何正确设置?

采纳答案by rsebbe

I ran into something similar but with static libs.

我遇到了类似的东西,但使用静态库。

  • Do what you did to build the framework, build your app (even if it fails, the framework should build)
  • Remove the reference to the framework in your app target's link build phase
  • Locate the built framework in the Finder (the one built by your app workspace).
  • drag/drop it into the app project that uses it. Notice that this time it appears with black color (not red)
  • click it, and make sure the Xcode inspector shows "relative to built products" (you may need to change it reference type), and that the path is just the myframework.framework.
  • check that it has been added to the app link phase (it should)
  • that's the one you can use in the copy/build phase.
  • 做你为构建框架所做的事情,构建你的应用程序(即使它失败了,框架也应该构建)
  • 在应用程序目标的链接构建阶段删除对框架的引用
  • 在 Finder 中找到构建的框架(由您的应用工作区构建的框架)。
  • 将它拖/放到使用它的应用程序项目中。请注意,这次它以黑色(不是红色)出现
  • 单击它,并确保 Xcode 检查器显示“相对于构建的产品”(您可能需要更改它的引用类型),并且路径只是 myframework.framework。
  • 检查它是否已添加到应用程序链接阶段(应该)
  • 这是您可以在复制/构建阶段使用的那个。