开发者

Adding Preprocessor directive dynamically from commandline build VS2008

I am using VS2008, and developing C/C++ projects. I am using .bat file to build my projects from commandline (VC2k8 command prompt). I need a way to include preprossor directive dynamically at build time.

I am using devenv to build from command line.

>devenv my\project\p开发者_Go百科ath\myproject.sln /build release > logs\build.log

Actually I want to set a macro definition based on a command line parameter to the batch file. I can keep two different .vcproj files, but that gives problem in keeping multiple project/sln files. My batch file would something like this...

if (condition)
#define MYPROC_ENABLE_MYMODULE "yes" // To be included in the project.
else
#define MYPROC_ENABLE_MYMODULE "no"

Any help would be really appreciated.

Thanks.


One option would be to set the CL environment variable, using something like:

set CL=/DMYPROC_ENABLE_MYMODULE

The C++ compiler (cl.exe) will add the contents of the CL environment variable to its command line when it runs.

I know you can define macros if you build using msbuild, but I'm not sure you can do the same when using devenv directly.


You can make different configurations for your solution and define different preprocessor flags for the different configurations. Then you would just need to select the configuration at the command line and no need for multiple solution or project files.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜