简体   繁体   English

Xcode项目模板:如何指定静态库依赖项?

[英]Xcode project templates: How can I specify a static library dependency?

I am trying to create an Xcode project template that contains two compilable targets, with one target (an app) dependent on the other (a static lib). 我正在尝试创建一个包含两个可编译目标的Xcode项目模板,其中一个目标(一个应用程序)依赖于另一个目标(一个静态库)。

Everything works so far, except that I cannot figure out how to specify the actual dependency in the template so that it shows up in the Target Dependencies section of the Build Phases tab of the app target of an Xcode project created from the template. 到目前为止,一切工作正常,除了我无法弄清楚如何在模板中指定实际的依赖关系,以便它显示在通过模板创建的Xcode项目的应用程序目标的“构建阶段”选项卡的“目标依赖关系”部分中。

I've configured the TemplateInfo.plist of the project as follows: 我已将项目的TemplateInfo.plist配置如下:

包含静态lib依赖项的项目的TemplateInfo.plist

The Components section identifies the static library project template and successfully brings the contents of that template, and its target, into the app project. “组件”部分标识了静态库项目模板,并将该模板的内容及其目标成功地带入了应用程序项目。 And once everything is compiled, the static library is successfully linked in the end, by Item 3 in the OTHER_LDFLAGS entry. 编译完所有内容后,最后将通过OTHER_LDFLAGS条目中的项目3成功链接静态库。

But try as I might, the Dependencies section of the template does not cause the static lib to appear in the Target Dependencies section of the Build Phases tab of the app target. 但是,请尝试尝试,模板的“依赖关系”部分不会导致静态库出现在应用程序目标的“构建阶段”选项卡的“目标依赖关系”部分中。 I've tried specifying the dependency using the numeric values 0 and 1, and I've tried it as a string using the name of the static library target (cocos2d), but none of these work. 我尝试使用数字值0和1指定依赖项,并尝试使用静态库目标(cocos2d)的名称将其作为字符串使用,但是这些都不起作用。

In the end, in each Xcode project created from this template, I'm left with users having to perform the step of navigating to the Target Dependencies section of the Build Phases tab of the app target, and manually selecting and adding the static library target. 最后,在通过该模板创建的每个Xcode项目中,我都需要执行以下步骤:导航到应用程序目标的“构建阶段”选项卡的“目标依赖项”部分,然后手动选择并添加静态库目标。 Although this is a relatively simple task, it shouldn't be necessary at all. 尽管这是一个相对简单的任务,但完全没有必要。

Can anyone advise me on how to configure the template dependencies so this manual step is not necessary? 谁能为我提供有关如何配置模板依赖项的建议,因此无需执行此手动步骤?

As you've indicated, the Dependancies tag under Targets references target array indices. 如您所指出的, Targets下的Dependancies标记引用目标数组索引。 In the example you've posted, your dependency is under Components . 在您发布的示例中,您的依赖项位于Components下。

Components appear to be add as targets after the targets from your template file are added to the project. 在将模板文件中的目标添加到项目之后,组件似乎被添加为目标。 If you reference the Cocoa Touch Application template provided with Xcode, Cocoa Touch Application Unit Testing Bundle is included as a component. 如果您参考Xcode随附的Cocoa Touch应用程序模板,那么Cocoa Touch应用程序单元测试包将作为组件提供。

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Temlpates/Application /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Temlpates / Application

可可触摸应用程序-TemplateInfo.plist

Looking at the plist for the Cocoa Touch Application Unit Testing Bundle , there is a dependency on target 0. Given components appear to be added after "local" targets, target 0 is present in the project when the unit test target is added and a dependency is created against the primary target. 查看Cocoa Touch应用程序单元测试捆绑包的plist,它与目标0有依赖关系。给定组件似乎是在“本地”目标之后添加的,当添加了单元测试目标时,项目0中存在目标0是针对主要目标创建的。

可可触摸应用程序单元测试套件-TemplateInfo.plist

Attempting this in reverse by adding a dependency on target 1 in the Cocoa Touch Application does not work. 通过在Cocoa Touch应用程序中添加对目标1的依赖关系来反向尝试此操作不起作用。

The only work around that I've been able to find is to move Components to Ancestors and duplicate the Targets items from each component in the Targets section of your template. 我唯一能找到的解决方法是将“ 组件”移至“ 祖先”,并在模板的“ 目标”部分中复制每个组件中的“ 目标”项。 From there you can reference the indices of any components included in your targets array. 从那里,您可以引用目标数组中包含的任何组件的索引。

You should note that even with this technique, targets appear to be added to the project in order and you only seem to be able to set dependancies on indices that have already been added (ie index 0 cannot reference index 2). 您应该注意,即使采用这种技术,目标似乎仍会按顺序添加到项目中,并且您似乎只能对已添加的索引设置依赖关系(即索引0不能引用索引2)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用链接到此静态库的项目计算XCode 5中静态库的代码覆盖率? - How can i calculate code coverage of a static library in XCode 5 using a project that links to this static library? 如何在Xcode模板中包含静态库依赖项? - How do I include a static library dependency in an Xcode Template? 在XCode4 iOS项目中有条件地指定外部静态库? - Conditionally specify an external static library in an XCode4 iOS project? 如何为Xcode项目指定其他clang选项? - How can I specify additional clang options for Xcode project? 如何将现有的xcode项目转换为静态库 - how to convert existing xcode project to static library 如何将Xcode项目重用到新项目中? 静态库,框架,目标? - How to reuse an Xcode project into a new project? Static library, Framework, Targets? 将xcode项目转换为静态库 - Converting xcode project to static library 如何从现有的xcode项目中创建一个统一的静态iOS库 - how to create a static iOS library for unity from an existing xcode project 如何在Xcode 4中创建项目模板 - How to create project templates in Xcode 4 如何更改静态库的代码.a文件Xcode项目的另一个Xcode项目? - How to change code of static library .a file Xcode Project for another Xcode project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM