Reputation: 13234
The documentation tells me that /D
command-line switch can be used to do this, like so:
CL /DDEBUG TEST.C
This would define a DEBUG symbol, and
CL /DDEBUG=2 TEST.C
would give it the value 2.
But what do I do if I would like to get the equivalent of a string define, such as the following?
#define DEBUG "abc"
Upvotes: 5
Views: 5869
Reputation: 21721
I don't have VC to test this for you, however, in principle the following should work:
CL /DSTRINGIFY(X)=#X /DDEBUG=STRINGIFY(abc) TEST.C
As highlighted by Kuba hasn't forgotten Monica, VC doesn't seem to do the right thing here. Testing with a simple example, it generates:
const char * s = STRINGIFY(abc);
It may 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";
Upvotes: -1
Reputation: 154
This works for me in Visual Studio 2013:
/D_STRING="\"abc\""
Then it is equivalent to
#define _STRING "abc"
Note, if you do
/D_STRING="abc"
It will be equivalent to
#define _STRING abc
Upvotes: 2
Reputation: 13234
The second one could work on the command line, but the coworker I've asked this for eventually used this in the project definition (needing to escape the double-quotes and replace = with #):
/DDEBUG#\"abc\"
Upvotes: 1
Reputation: 32635
Due to the way command line is parsed in Windows, you'll have to escape the quotes.
CL /DDEBUG=\"abc\" TEST.C
Upvotes: 5