如何使用命令行将“其他链接器标志”添加到 xcode 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11147626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:39:43  来源:igfitidea点击:

How to add "Other Linker Flags" to xcode project using command line?

iphoneiosxcodexcodebuild

提问by almas

I'm trying to automate building process of xcode project. The problem is that I need to add "Other Linker Flags" when building the project. I can't just add it to the project Build Settings manually, I have to do it using the command line. May be I can edit the project file or configuration file somehow? Any options are good as long as it can be runned as a script. Any ideas? Thanks

我正在尝试自动化 xcode 项目的构建过程。问题是我需要在构建项目时添加“其他链接器标志”。我不能只是手动将它添加到项目 Build Settings 中,我必须使用命令行来完成。也许我可以以某种方式编辑项目文件或配置文件?只要可以作为脚本运行,任何选项都是好的。有任何想法吗?谢谢

采纳答案by Jesse Rusak

You can do this by specifying an xcconfig file to xcodebuild. For example:

你可以通过为 xcodebuild 指定一个 xcconfig 文件来做到这一点。例如:

echo 'OTHER_LDFLAGS = $(OTHER_LDFLAGS) -force_load "$(SRCROOT)/calabash.framework/calabash" -lstdc++' > temp.xcconfig
xcodebuild -xcconfig temp.xcconfig ...

回答by Paul Beusterien

@Jesse Rusak's answer works, but it is a bit simpler to directly add options to the command line, being careful to escape variables from your shell like

@Jesse Rusak 的答案有效,但直接向命令行添加选项要简单一些,注意从 shell 中转义变量,例如

xcodebuild ... "OTHER_LDFLAGS=$(OTHER_LDFLAGS) -all_load"

回答by user3288724

open up the project.pbxproj file in an editor like BBEdit and paste in the flags you want. Search for

在像 BBEdit 这样的编辑器中打开 project.pbxproj 文件并粘贴你想要的标志。搜索

buildSettings = {
...

SWIFT_VERSION = 4.2;
}

becomes

变成

buildSetting = {
...

SWIFT_VERSION = 4.2;
OTHER_LDFLAGS = "-all_load";
}

There should be a section for your Debug and Release schemes. Do it for all

应该有一个部分用于您的调试和发布方案。为所有人做