【问题标题】:Passing preprocessor variable to nmake build environment将预处理器变量传递给 nmake 构建环境
【发布时间】:2012-06-11 22:48:32
【问题描述】:

我在 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?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-03
      • 1970-01-01
      • 2013-12-29
      • 2015-09-18
      • 2021-09-05
      • 2020-03-27
      • 2017-03-30
      • 2018-08-19
      相关资源
      最近更新 更多