在 Xcode 4 项目模板中包含 libsqlite3 dylib
我为 iOS 创建了一个 Xcode 4 项目模板,它依赖于多个框架和 libsqlite3.dylib。我已经能够自动添加框架,但似乎无法弄清楚如何添加 dylib。有人有这样的运气吗?
编辑:
我想我还不够清楚,我创建了自己的 .xcodetemplate 文件,当我创建新项目时,该文件显示为项目模板。我需要知道在 TemplateInfo.plist 文件中放置什么,以便将 libsqlite3.dylib 文件包含在从模板创建的新项目中。我已经成功地添加了 .framework 文件,例如 CoreMotion,方法是将它们列在 Targets->Item 0->Frameworks 键下,但这不适用于 dylib。
I have created an Xcode 4 project template for iOS that relies on several frameworks and the libsqlite3.dylib. I have been able to get the frameworks added automatically but can't seem to figure out how to add a dylib. Has anyone had any luck with this?
Edit:
I suppose I wasn't clear enough, I have created my own .xcodetemplate file that appears as a project template when I create a new project. I need to know what to place in the TemplateInfo.plist file to have the libsqlite3.dylib file included in new projects created from the template. I have been successfully able to add .framework files such as CoreMotion by listing them under the Targets->Item 0->Frameworks key, but this doesn't work for dylibs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一种通过“其他链接器标志”项目设置来执行此操作的方法。要链接 sqlite3.0.dylib 框架,只需在 Project->SharedSettings 下的 TemplateInfo.plist 中添加一个节点,其中键为“OTHER_LDFLAGS”,值为“-lsqlite3.0”。
请注意,这将覆盖项目模板的所有“其他链接器标志”,许多人将其用于诸如 -ObjC 之类的标志;因此,如果您也想保留这些标志,只需列出您想要的所有标志,并在它们之间留一个空格。 IE:如果您希望项目模板包含 ObjC 链接器标志和 sqlite,只需将节点的值设置为“-ObjC -lsqlite3.0”。
对于那些好奇我是如何弄清楚的人,我使用目标的“构建阶段”选项卡手动将 sqlite3.0.dylib 框架添加到我的项目中,然后构建项目。然后,我通过单击 Xcode 中的日志导航器选项卡查看了构建的详细信息。然后,我单击最新的构建以查看其详细信息,并通过单击文本右侧的详细信息披露按钮来展开构建详细信息的“链接”部分。在那里,我看到了它所链接的所有库和框架的列表:
在框架列表中,我发现“-lsqlite3.0”作为链接库之一。将“lsqlite3.0”添加到其他链接库基本上可以完成相同的事情。如果您想将任何其他 dylib 框架添加到模板中,只需遵循相同的过程:将它们添加到目标的构建阶段,检查构建脚本以查看链接时实际调用的库,然后将它们添加到TemplateInfo.plist 中的 OTHER_LDFLAGS 列表。
注意:以这种方式添加库不会将框架添加到 XCode 中的构建阶段 UI,但仍会正确链接它。
I found a way to do this through the Other Linker Flags project settings. To link the sqlite3.0.dylib framework, just add a node to your TemplateInfo.plist under Project->SharedSettings with the Key "OTHER_LDFLAGS" and the value "-lsqlite3.0".
Note that this will override all of the "Other Linker Flags" for your project template, which many people use for flags such as -ObjC; so, if you want to keep those flags as well just make a list of all flags you want with a space in between them. IE: if you want your project template to include the ObjC linker flag and sqlite, just set the value of the node to "-ObjC -lsqlite3.0".
For those of you curious how I figured it out, I added the sqlite3.0.dylib framework to my project manually using the Build Phases tab of my target, and then built the project. I then looked at the details of the build by clicking on the log navigator tab in Xcode. I then clicked on the most recent build to see its details, and expanded the "link" section of the build details by clicking on the detail disclosure button at the very right of the text. There I saw a a list of all the libraries and frameworks that it was linking against:
In the list of frameworks I found "-lsqlite3.0" as one of the linked libraries. Adding "lsqlite3.0" to the other linked libraries basically accomplishes the same thing. If there are any other dylib frameworks you want to add to your template, just follow this same process: Add them to your target's build phases, check the build script to see what the library is actually called at link time, and then add them to your list of OTHER_LDFLAGS in your TemplateInfo.plist.
NOTE: Adding the libraries in this way will not add the frameworks to the build phases UI in XCode, but it will still link it correctly.