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

查看:127
本文介绍了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)"

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

作为一个额外的好处,如果您知道宏不会影响预编译的前缀文件的内容,那么您应该使用未在预编译头文件中使用的预处理器宏,而不是预处理器宏. .

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.

这样,您可以改善项目中甚至不同项目之间的预编译前缀头文件(由文件定义)的共享. 技术说明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天全站免登陆