开发者

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 like WIN32;_DEBUG;_CONSOLE;$(AdditionalPreprocessorDefinitions);%(PreprocessorDefinitions)

  • Use msbuild instead of devenv to start the build process

  • Specify 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜