devenv and #define
I'm building some projects using cmd devenv.
For some projects I want to #define form the command line.
Is there a way to #define using the cmd and开发者_运维技巧 devenv? I don't want to create new configurations.
You could do this:
Add
$(AdditionalPreprocessorDefinitions)
to the list of preprocessor definitions of the project. After that, they might look likeWIN32;_DEBUG;_CONSOLE;$(AdditionalPreprocessorDefinitions);%(PreprocessorDefinitions)
Use
msbuild
instead ofdevenv
to start the build processSpecify the additional preprocessor definitions by adding
/p:AdditionalPreprocessorDefinitions="SOMEDEF;ANOTHERDEF"
to the command line.
Please not that I picked the name AdditionalPreprocessorDefinitions just for clarity, you can pick something shorter. This will only work with VC2010, because in earlier versions, VC++ projects were not built with msbuild.
Many compilers allow you to set define macros at the command line. The common option is "-D".
Check your compiler documentation for exact syntax.
Edit 1: The Visual Studio compiler has configuration options to specify the macros in the IDE (which get passed to the compiler using the "-D" switch.)
You can not do this with devenv.exe, see the Command Line Options. You can do this with the compiler however, cl.exe but then you can't reuse all the settings in your project file.
精彩评论