Adding libraries/Frameworks to Xcode project using the command line?

我的未来我决定 提交于 2019-12-20 02:54:10

问题


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

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

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


回答1:


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)

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.

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.



来源:https://stackoverflow.com/questions/16422501/adding-libraries-frameworks-to-xcode-project-using-the-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!