Xcode 中特定文件的特定编译器标志

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2764735/
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-14 19:19:40  来源:igfitidea点击:

Specific compiler flags for specific files in Xcode

iphonexcodeios-simulatorcompiler-flags

提问by Jasarien

I've been tasked to work on a project that has some confusing attributes.

我的任务是处理一个具有一些令人困惑的属性的项目。

The project is of the nature that it won't compile for the iPhone Simulator And the iPhone Device with the same compile settings. I think it has to do with needing to be specifically compiled for x86 or arm6/7 depending on the target platform.

该项目的性质是它不会为具有相同编译设置的 iPhone 模拟器和 iPhone 设备编译。我认为这与需要根据目标平台专门为 x86 或 arm6/7 编译有关。

So the project's build settings, when viewed in Xcode's Build Settings view doesn't enable me to set specific compiler flags per specific files. However, the previous developer that worked on this project has somehow declared the line:

因此,在 Xcode 的 Build Settings 视图中查看项目的构建设置时,我无法为每个特定文件设置特定的编译器标志。但是,参与该项目的前任开发人员以某种方式声明了以下内容:

CE7FEB5710F09234004DE356 /* MyFile.m in Sources */ = {isa = PBXBuildFile; fileRef = CE7FEB5510F09234004DE356 /* MyFile.m */; settings = {COMPILER_FLAGS = "-fasm-blocks -marm -mfpu=neon"; }; };

Is there any way to do this without editing the project file by hand? I know that editing the project file can result in breaking it completely, so I'd rather not do that, as I obviously don't know as much as the previous developer.

有没有办法在不手动编辑项目文件的情况下做到这一点?我知道编辑项目文件可能会导致完全破坏它,所以我宁愿不这样做,因为我显然不像以前的开发人员那样了解。

So to clarify, the question is:

所以澄清一下,问题是:

The build fails when compiling for simulator unless I remove the -fasm-blocksflag. The build fails when compiling for device unless I add the -fasm-blocksflag. Is there a way to set this flag per file without editing the project file by hand?

除非我删除-fasm-blocks标志,否则编译模拟器时构建会失败。除非我添加-fasm-blocks标志,否则编译设备时构建会失败。有没有办法在不手动编辑项目文件的情况下为每个文件设置这个标志?

采纳答案by Paul R

You can define additional compiler flags for individual source files as follows:

您可以为各个源文件定义额外的编译器标志,如下所示:

  • first select the target you are going to build
  • right click on the source file
  • select "Get Info"
  • click on the "Build" tab
  • define your additional compiler flags
  • 首先选择你要构建的目标
  • 右键单击源文件
  • 选择“获取信息”
  • 单击“构建”选项卡
  • 定义额外的编译器标志

However it sounds like a better solution in your case is just to duplicate the target and have two targets - one for an actual device and one for the simulator. Inherit common build settings from the project level and just tweak the per-target build settings as necessary.

但是,在您的情况下,听起来更好的解决方案是复制目标并有两个目标 - 一个用于实际设备,一个用于模拟器。从项目级别继承通用构建设置,并根据需要调整每个目标的构建设置。

回答by Rob VS

Thisblog post by Joshua Nozzi explains how to do this in Xcode 4, where he says:

Joshua Nozzi 的这篇博文解释了如何在 Xcode 4 中执行此操作,他说:

... select your project in the Project Navigator, select the relevant target (you may have only one), then select the Build Phases tab. Expand the Compile Sources phase and viola! A Compiler Flags column lets you set each file's flags for that target.

... 在 Project Navigator 中选择您的项目,选择相关目标(您可能只有一个),然后选择 Build Phases 选项卡。展开编译源阶段和中提琴!Compiler Flags 列允许您为该目标设置每个文件的标志。

回答by Jens

Call GetInfo for the specific file, you can set the Build settings there for this file. See also the XCode Project Management Guide about this.

为特定文件调用 GetInfo,您可以在那里为该文件设置 Build 设置。另请参阅有关此内容的 XCode 项目管理指南。