将预处理器变量传递给nmake构建环境

时间:2012-06-11 22:48:33

标签: c++ c-preprocessor visual-studio-2005 nmake wdk

我遇到在Win7 x64构建环境中使用nmake构建驱动程序的问题。我正在定义一个预处理器变量,并使用 -

将其传递给命令行
build /nmake "USER_C_FLAGS=/DMyVersion=3"

构建日志是 -

...
/DMyVersion=3
/typedil- 
/wd4603
/wd4627
....

因此,我清楚地将变量视为编译器选项的一部分。现在在标题中,我做了

#define otherVersion 10
#ifdef MyVersion
  #undef otherVersion
  #define otherVersion MyVersion
#endif

#define FileVersion otherVersion

问题是FileVersion始终 10 ,无论环境中是否传递了MyVersion定义。为了测试,发生了什么,我做了 -

#ifdef MyVersion
  #error MyVersion is present in the environment.
#endif

我看到正在打印的声明。但是,尽管环境中存在预处理器指令,为什么otherVersion总是 10 ?为什么不通过命令行选项传递值 3

1 个答案:

答案 0 :(得分:1)

我不确定,如果这对您有用,但有些人确实尝试使用msbuild实现完全相同。他们必须调整项目文件以将其定义“导入”构建过程。看看MSBuild.exe not accepting either /p:DefineConstants nor /p:PreprocessorDefinitions