xcode 在Xcode中添加项目依赖

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9753494/
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-14 23:41:19  来源:igfitidea点击:

Add project dependencies in Xcode

iosxcodeios-simulator

提问by LKS

I am working with the AR Drone to develop new application.

我正在与 AR Drone 合作开发新应用程序。

I want to establish a dependency between two projects. So when I compile one, I hope Xcode will help compile the another one automatically. I had searched with Google for this question. The solutions found are quite old and not applicable for Xcode 4.

我想在两个项目之间建立依赖关系。所以当我编译一个的时候,我希望 Xcode 会帮助自动编译另一个。我曾用谷歌搜索过这个问题。找到的解决方案很旧,不适用于 Xcode 4。

Right now, I have two project, namely, ARDroneEngine.xcodeproj and FreeFlight.xcodeproj.

现在,我有两个项目,分别是 ARDroneEngine.xcodeproj 和 FreeFlight.xcodeproj。

ARDroneEngine is a library for FreeFlight. Here comes the screenshot.

ARDroneEngine 是 FreeFlight 的库。截图来了。

enter image description here

在此处输入图片说明

If I compile FreeFlight with iPhone / iPad simulator, it is fine since the ARDroneEngine is last compiled with the same setting. This is where the question lies. To test my application, I want to compile and run FreeFlight in my iPhone. So when I change the setting to "FreeFlight > xxx's iPhone" and compile, the error occurs: "Apple Mach-O Linker Error".

如果我用 iPhone/iPad 模拟器编译 FreeFlight,那很好,因为 ARDroneEngine 上次编译时使用相同的设置。这就是问题所在。为了测试我的应用程序,我想在我的 iPhone 中编译和运行 FreeFlight。因此,当我将设置更改为“FreeFlight > xxx's iPhone”并编译时,会出现错误:“Apple Mach-O Linker Error”。

I think the problem is rooted from the Target Dependencies between two projects. A quick workaround will be: Compile the ARDroneEngine again with the new Scheme "ARDroneEngine > xxx's iPhone" and launch FreeFlight in Xcode for my iPhone.

我认为问题源于两个项目之间的目标依赖关系。一个快速的解决方法是:使用新方案“ARDroneEngine > xxx's iPhone”再次编译 ARDroneEngine 并在 Xcode 中为我的 iPhone 启动 FreeFlight。

But I want a more complete solution with the dependencies between projects. If more information is required to solve the problem, I can always provide new info.

但我想要一个更完整的解决方案,其中包含项目之间的依赖关系。如果需要更多信息来解决问题,我可以随时提供新信息。

Thanks, Steven

谢谢,史蒂文

回答by rickster

Xcode's solution to cases like this is to use a Workspace that encompasses both projects: then, when one project has a target that references the build product of another, it automagically works out the dependencies and builds them in order.

Xcode 对此类情况的解决方案是使用包含两个项目的工作区:然后,当一个项目的目标引用另一个项目的构建产品时,它会自动计算依赖项并按顺序构建它们。

  1. Create a new Workspace (File > New > Workspace); name it and save it anywhere you like (though putting it in a parent folder to both project directories might be a good idea).
  2. Add both projects (drag the xcodeproj files from the Finder into the navigator pane, or use File > Add Files).
  3. Expand the Products group of your library project so you can see the (placeholder for the) built library (libARDroneEngine.a).
  4. Select the app project (FreeFlight) in the navigator and its app target in the editor -- you should be looking at the Summary pane for the target (the one with bundle identifier, deployment info, entitlements, and most importantly, the "Linked Frameworks & Libraries" list).
  5. Drag the library (libARDroneEngine.a) from the navigator (where you made it visible in step 3) into the Linked Frameworks & Libraries list.
  1. 创建一个新的工作区(文件 > 新建 > 工作区);命名并将其保存在您喜欢的任何位置(尽管将其放在两个项目目录的父文件夹中可能是个好主意)。
  2. 添加两个项目(将 xcodeproj 文件从 Finder 拖到导航器窗格中,或使用文件 > 添加文件)。
  3. 展开您的库项目的 Products 组,以便您可以看到(该库的占位符)构建的库 (libARDroneEngine.a)。
  4. 在导航器中选择应用程序项目 (FreeFlight) 并在编辑器中选择它的应用程序目标——您应该查看目标的“摘要”窗格(具有包标识符、部署信息、权利,最重要的是,“链接框架”和库”列表)。
  5. 将库 (libARDroneEngine.a) 从导航器(您在步骤 3 中使其可见的位置)拖到 Linked Frameworks & Libraries 列表中。

That's it! Now you can choose the FreeFlight > xxx scheme and it'll automatically build the library project before building the app.

就是这样!现在您可以选择 FreeFlight > xxx 方案,它会在构建应用程序之前自动构建库项目。

You can probably get a more complete summary of these instructions (with screenshots and all) in the Xcode help for Workspaces.

您可能可以在工作区的 Xcode 帮助中获得这些说明的更完整摘要(包括屏幕截图和所有内容)。