How do I make a line preprocessor definition from the command line in VC 2005 (C ++)?

the documentation tells me that the D command line switch can be used for this, e.g .:

  CL /DDEBUG TEST.C

      

will define a DEBUG character and

  CL /DDEBUG=2 TEST.C

      

will give it the value 2. But what if I would like to get the equivalent of a string definition, like

  #define DEBUG "abc"

      

?

+2


source to share


5 answers


Due to the way Windows parses the command line, you'll have to avoid quotes.



CL /DDEBUG=\"abc\" TEST.C

      

+5


source


You tried

CL /DDEBUG=abc TEST.C

      



or

CL /DDEBUG="abc" TEST.C

      

+2


source


Thanks Glen, the second one might work on the command line, but a colleague I asked ended up using this in the project definition (need to avoid double quotes and replace = C #):

/DDEBUG#\"abc\"

      

+1


source


This works for me in VS2013:

/D_STRING="\"abc\""

      

then it is equivalent

#define _STRING "abc"

      

Please note that if you do

/D_STRING="abc"

      

It will be equivalent to

#define _STRING abc

      

0


source


I don't have a VC to test this for you, however in principle the following should work:

CL /DSTRINGIFY(X)=#X /DDEBUG=STRINGIFY(abc) TEST.C

      

Update:

As Coober-Aubert stressed, VC doesn't seem to be doing the right thing here. Testing with a simple example generates:

const char * s = STRINGIFY(abc);

      

It can work with other compilers, for example the following g ++ command line works:

g++ -D'STRINGIFY(X)=#X' -D'DEBUG=STRINGIFY(abc)' t.cc -E

# 1 "t.cc"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "t.cc"

const char * s = "abc";

      

-1


source







All Articles