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

查看:470
本文介绍了使用命令行将库/Frameworks添加到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.

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

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