问题
I am having issues with building driver using nmake
on Win7 x64 build environment. I am defining a preprocessor variable and passing it over the command line using -
build /nmake "USER_C_FLAGS=/DMyVersion=3"
And the build log is -
...
/DMyVersion=3
/typedil-
/wd4603
/wd4627
....
So, I clearly see the variable as part of the compiler options. Now in a header fie, I do
#define otherVersion 10
#ifdef MyVersion
#undef otherVersion
#define otherVersion MyVersion
#endif
#define FileVersion otherVersion
The problem is FileVersion
is always being 10 irrespective of the MyVersion
define passed and exist in the environment. To test, what is going on, I did -
#ifdef MyVersion
#error MyVersion is present in the environment.
#endif
I see the statement being printed. But why is otherVersion
is always 10 despite the preprocessor directive is present in the environment ? Why it is not taking the value 3 passed via command line options?
回答1:
I'm not sure, if this works for you, but some people did try to achieve quite the same using msbuild. They had to adapt the project-file to pipe their definitions "into" the build-process. Have a look at MSBuild.exe not accepting either /p:DefineConstants nor /p:PreprocessorDefinitions
来源:https://stackoverflow.com/questions/10988501/passing-preprocessor-variable-to-nmake-build-environment