How do I use the C preprocessor to make a substitution with an environment variable(如何使用 C 预处理器使用环境变量进行替换)
问题描述
在下面的代码中,我希望 THE_VERSION_STRING
的值在编译时取自环境变量 MY_VERSION
的值
In the code below, I would like the value of THE_VERSION_STRING
to be taken from the value of the environment variable MY_VERSION
at compile time
所以如果我输入:
pluginRequires
将设置为2010.4",即使 MY_VERSION
在运行时设置为其他值.
pluginRequires
will be set at "2010.4", even if MY_VERSION
is set to something else at run time.
更新:(2 月 21 日)感谢大家的帮助.有用.当我使用 Rake 作为构建系统时,我的每个 CFLAGS 都是一个 ruby 变量.此外,这些值需要以引号结尾.因此,我的 gcc 命令行需要如下所示:
UPDATE: (feb 21) Thanks for your help everyone. It works. As I'm using Rake as a build system, each of my CFLAGS is a ruby variable. Also the values need to end up in quotes. Therefore the gcc command line for me needs to look like this:
这意味着这在我的 Rakefile 中:
Which means this is in my Rakefile:
推荐答案
如果我没记错的话,可以使用命令行参数-D
用 gcc 在编译时为 #define
一个值.
If I recall correctly, you can use the command line parameter -D
with gcc to #define
a value at compile time.
即:
这篇关于如何使用 C 预处理器使用环境变量进行替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!