简体   繁体   English

如何在Xcode模板中包含静态库依赖项?

[英]How do I include a static library dependency in an Xcode Template?

I can include a framework like so in a TemplateInfo.plist file: 我可以在TemplateInfo.plist文件中包含这样的框架:

<key>Frameworks</key>
            <array>
                <string>QuartzCore</string>
                <string>OpenGLES</string>
                <string>OpenAL</string>
                <string>AudioToolbox</string>
                <string>AVFoundation</string>
                <string>UIKit</string>
                <string>Foundation</string>
                <string>CoreGraphics</string>
            </array>

But I cannot find how to do something similar with static libraries. 但我找不到如何使用静态库做类似的事情。 This would greatly improve my template. 这将大大改善我的模板。 Is there such functionality? 有这样的功能吗?

I found a solution. 我找到了解决方案。

In templateInfo.plist add key Targets --> SharedSettings 在templateInfo.plist中添加关键目标 - > SharedSettings

<key>OTHER_LDFLAGS</key>
<string>ObjC -all_load -weak_library /usr/lib/libz.dylib ..</string>

It adds your dylib to debug and run settings.. doesn't work with autocomplete as xcode can do with frameworks, but still lot better than doing it manually 它将你的dylib添加到调试和运行设置..不能使用自动完成,因为xcode可以用于框架,但仍然比手动更好

EDIT: expalin 编辑:expalin

<key>Targets</key>
<array>
    <dict>
        <key>Dependencies</key>
        <array><integer>0</integer></array>
        <key>Frameworks</key>
        <array>
            <string>CoreAudio</string>              
        </array>
        <key>SharedSettings</key>
        <dict>
            <key>OTHER_LDFLAGS</key>
            <string>-ObjC -all_load -weak_library /usr/lib/libz.dylib -weak_library /usr/lib/libstdc++.dylib </string>
        </dict>     
    </dict>

The best way I found for doing this is to create an alias to the /usr/lib directory inside your templates folder. 我发现这样做的最好方法是在templates文件夹中创建/ usr / lib目录的别名。 From there, you can access all the libs which are in /usr/lib, even the ones which are aliases themselves. 从那里,您可以访问/ usr / lib中的所有库,甚至是别名本身的库。

First, I create templates by editing the .plists in XCode, not by editing the xml representations themselves. 首先,我通过在XCode中编辑.plists来创建模板,而不是通过编辑xml表示本身。 So, that's how I will be explaining the steps I took to include static libraries into my template. 所以,这就是我将如何解释我将静态库包含到模板中的步骤。


1) I have a project template: iPhoneOS.platform / Developer / Library / Xcode / Templates / Project Templates / Application / C4 Application.xctemplate 1)我有一个项目模板:iPhoneOS.platform / Developer / Library / Xcode / Templates / Project Templates / Application / C4 Application.xctemplate

(In Xcode 4.3 the Project Templates / Application can be found directly in the Xcode.app by right-clicking the bundle and choosing Show Package Contents) (在Xcode 4.3中,可以直接在Xcode.app中找到项目模板/应用程序,方法是右键单击该包并选择“显示包内容”)

图片

The guts of this folder look like this: 这个文件夹的内容如下所示:

图片

2) As you can see in the image above, I created an alias for the lib folder ( /usr/lib ) that contains static libraries and moved the alias into my .xctemplate folder. 2)正如您在上图中看到的,我为包含静态库的lib文件夹( /usr/lib )创建了一个别名,并将别名移动到我的.xctemplate文件夹中。

图片

3) In my TemplateInfo.plist file I specify 2 things: a Dictionary and a Node. 3)在我的TemplateInfo.plist文件中,我指定了两件事:一个字典和一个节点。 I put them inside the Definitions and Nodes of the TemplateInfo.plist 我把它们放在TemplateInfo.plist的Definitions和Nodes中

图片

First, in the Definitions node I specify a dictionary called: Libs/libalias.dylib 首先,在Definitions节点中,我指定一个名为:Libs / libalias.dylib的字典

Inside this lib I have 2 strings Group : Libs Path : lib/libalias.dylib 在这个lib里面我有2个字符串组:Libs Path:lib / libalias.dylib

The node looks like this: 该节点如下所示:

图片

It is important that the syntax be exactly like this, and most importantly that the name of the Dictionary itself specifies the library you want to import. 重要的是语法必须与此完全相同,最重要的是,Dictionary本身的名称指定了要导入的库。 In this case I am importing the libalias.dylib library. 在这种情况下,我正在导入libalias.dylib库。

It is also important that the Path be lib/libalias.dylib because this will point to the alias which points to your /usr/lib folder. Path是lib / libalias.dylib也很重要,因为这将指向指向/ usr / lib文件夹的别名。

Second, in the Nodes array I specify an item as a string which is called Libs/libalias.dylib (note: the exact same name as the Dictionary I specified in Definitions) 其次,在Nodes数组中,我将一个项指定为一个名为Libs / libalias.dylib的字符串(注意:与我在Definitions中指定的字典完全相同)

图片

This is what the Node Item should look like. 这就是节点项应该是什么样子。

4) Once you have these things set up, you can create a new project with your lib already included. 4)设置完这些内容后,您可以创建一个包含lib的新项目。

图片

NOTE: because I called my Dictionary Libs/... and specified it's Group as Libs the library I am importing appears in a subfolder called Libs in my Project Navigator. 注意:因为我调用了我的Dictionary Libs / ...并将其指定为Group,因为我导入的库出现在我的Project Navigator中名为Libs的子文件夹中。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM