Is there a way to add extra preprocessor #define in devenv command line?
-
no, that's invalid syntax - it shows devenv help – Paulius Liekis Nov 23 '09 at 14:32
5 Answers
I am not entirely sure what you mean by vcbuild command line but if you mean the Visual C++ command line compiler then you can add defines by add /Dxxxx, e.g.
cl.exe /DSHAREWARE ....
Additional answer based on comments:
You should be able to set the CL environment variable with the extra preprocessor define:
SET CL=/DSHAREWARE
devenv ....
Mere information can be found at MSDN

- 6,977
- 1
- 26
- 27
-
I had in mind devenv.exe. cl only compiles IIRC. devenv does linking as well. – Paulius Liekis Nov 23 '09 at 13:59
-
That works fine - I just found the same answer somewhere else. Thanks anyway! – Paulius Liekis Nov 23 '09 at 15:05
-
Well, then you should accept the answer so others can see that this question is solved... – HakonB Nov 23 '09 at 15:23
in your project settings, add the following preprocessor definition:
$(MyPreprocessorDefinitions);
then in your *.bat file, use
REM #define MY_DEF
set MyPreprocessorDefinitions=MY_DEF
devenv.exe ...
REM #undefine MY_DEF
set MyPreprocessorDefinitions=

- 693
- 1
- 6
- 3
The #defines are defined in your Visual Studio project file (.dsp or .vcproj file). This is a simple text file. So you could edit the project file from a script, then call devenv.exe.

- 10,954
- 6
- 44
- 66
I couldn't find a way without modifying solution or project files so I came up with the following:
- Create empty file as part of build e.g.
feature_flag.h
- Replace
#if FEATURE_FLAG
with#if !__has_include("feature_flag.h")
- Remove
feature_flag.h
at the end of the build
It's not using #define but it does use the preprocessor which was what I needed.

- 2,776
- 3
- 26
- 42
In my case, I needed to use devenv for other reasons, (and was running in cygwin, so i had sed).
I set a Compilation symbol in the project's properties SED_REPLACE_THIS
and then used sed to set it to something meaningful (ie: DONT_CRASH_AS_MUCH
)
sed -i 's/SED_REPLACE_THIS/DONT_CRASH_AS_MUCH/g' project.csproj

- 9,227
- 9
- 65
- 92

- 31
- 3