使用命令行将库/框架添加到 Xcode 项目? [英] Adding libraries/Frameworks to Xcode project using the command line?

查看:26
本文介绍了使用命令行将库/框架添加到 Xcode 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用命令行将库添加到 Xcode 项目的方法.

I am looking for a way to add libraries to an Xcode project, using the command line.

我已成功使用 XCS 工具将文件添加到组,但它不支持图书馆.

I have been successful in adding files to groups with the XCS tool, but it does not support libraries.

例如,我希望能够使用终端上的命令将 CoreVideo.framework 添加到特定项目.

I would, for example, like to be able to add CoreVideo.framework to a specific project with a command on the Terminal.

推荐答案

这个项目可以处理框架:https://github.com/kronenthaler/mod-pbxproj

This project can handle frameworks: https://github.com/kronenthaler/mod-pbxproj

只需将其添加为普通文件,它就会找出正确的类型以及如何设置所有内容(即,将其添加到链接库阶段 - 在使用它之前,您仍然需要导入标头,当然).

Just add it as a normal file, it will figure out the correct type and how to set everything up (i.e., add it to the link library phase – before using it, you still need to import the header(s), of course).

    // libFilePath: Path to the framework
    frameworkGroup = project.get_or_create_group('Frameworks')
    project.add_file(libFilePath,
                     parent=frameworkGroup,
                     tree='SDKROOT',
                     weak=True)

您可以决定是否要弱链接框架(参见代码示例)(只需省略最后一个参数,它默认为 False).您可以在存储库中找到打开/保存 Xcode 项目的代码.

You can decide whether you want to weak-link frameworks (see code example) or not (just leave out the last parameter, it defaults to False). You can find the code to open/save Xcode projects in the repository.

另一种方法是直接添加链接器标志,例如,-framework CoreVideo.framework.如果框架路径设置正确,则不必提供绝对路径.这种方法的缺点是,如果您打开 Xcode 项目,链接的框架并不明显,因为它们不是链接库部分的一部分,而且该框架也不会显示在 Project Navigator 的任何 Xcode 组中.

Another way to do it is adding linker flags directly, e.g., -framework CoreVideo.framework. If the framework paths are set up correctly, you don't have to provide absolute paths. The disadvantage of this approach is that the linked frameworks aren't obvious if you open the Xcode project, as they are not part of the link library section, nor does the framework show up in any Xcode group in the Project Navigator.

这篇关于使用命令行将库/框架添加到 Xcode 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆