Xcode 预处理器宏 [英] Xcode Preprocessor Macros

查看:42
本文介绍了Xcode 预处理器宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Xcode 中,我可以在项目设置中编辑我的预处理器宏.我想创建一个引用环境变量的宏.基本上,我希望能够在我的代码中引用 $SRC_ROOT.我目前在宏中拥有的是:

In Xcode, I can edit my preprocessor macros in the project settings. I want to create a macro that refers to an environment variable. Basically, I want to be able to refer to $SRC_ROOT in my code. What I currently have in my macros is:

SRC_ROOT=${SRC_ROOT}

但它不起作用.

推荐答案

在 Xcode 构建设置中,您实际上并不是指的是环境变量值.相反,您指的是 构建设置 值.其语法是 Makefile 风格的 $(SETTING_NAME) 而不是你上面使用的 shell 风格的 ${SETTING_NAME}.

In Xcode build settings, you're not actually referring to an environment variable value. Instead, you're referring to a build setting value. The syntax for that is the Makefile-style $(SETTING_NAME) rather than the shell-style ${SETTING_NAME} you used above.

所以你要做的是添加

SRC_ROOT="$(SRCROOT)"

到您的预处理器宏构建设置.

另外,如果您知道宏不会影响预编译前缀文件的内容,那么您应该使用 Preprocessor Macros Not Used in Precompiled Headers 而不是 Preprocessor Macros 代替.

As an added bonus, if you know that your macros won't affect the contents of your precompiled prefix file, instead of Preprocessor Macros you should use Preprocessor Macros Not Used in Precompiled Headers instead.

这样,您可以改进项目中不同目标甚至不同项目之间预编译前缀标头(由 pch 文件定义)的共享.技术说明 2190:加速您的 Xcode 构建 对此有更详细的说明:如果您使用相同的前缀文件名和内容,并使用相同的构建设置进行构建,跨多个项目,您可以获得显着的构建性能改进,因为 Xcode 会识别它何时可以重用现有的预编译的前缀文件.

That way you can improve sharing of your precompiled prefix header (defined by a pch file) between different targets in your project, or even different projects. Technical Note 2190: Speeding up your Xcode Builds goes into more detail on this: If you use the same prefix file name and contents, and build using the same build settings, across multiple projects, you can get dramatic improvements in build performance because Xcode will recognize when it can re-use existing precompiled prefix files.

这篇关于Xcode 预处理器宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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