Define preprocessor symbol as a string containing spaces


December 2018


559 time


I'm working on a legacy project (in C, if that matters) that requires the use of MS Visual Studio 2008 SP1.

Specifically, one tool in the toolchain generates an MSVC makefile (.mak), which is then converted by a wizard in MSVC2008 to a project file (.vcproj), where it can be compiled/debugged.

I'm trying to define a pre-processor symbol (/D), which via the template makefile is set equal to an environment variable. The value of this environment variable is a string, possibly containing spaces.

I can't seem to find the right syntax for this, both by experiment or via Google. The wizard seems to be messing up quotes and spaces in a not-so-predictable manner...For example, if I put in the (generated) makefile

/D "MYSYMBOL=\"my string\"" /D "MYOTHERSYMBOL=\"someOtherString\"

Visual Studio's wizard erroneously puts the following in the project file:

/D /D "MYSYMBOL=\" my string\"" "MYOTHERSYMBOL=\" someOtherString\"

(note also the spaces after the escaped quotes).


input : /D "MYSYMBOL=\"my string\"" /D "MYOTHERSYMBOL=\"someOtherString\"
output: /D /D "MYSYMBOL=\" my string\"" "MYOTHERSYMBOL=\" someOtherString\" 

input : /D"MYSYMBOL=\"my string\"" /D"MYOTHERSYMBOL=\"someOtherString\"
output: /D"MYSYMBOL=\"my /D"MYOTHERSYMBOL=\"someOtherString\" string\""

input : /DMYSYMBOL=\"my string\" /DMYOTHERSYMBOL=\"someOtherString\
output: /DMYSYMBOL=\"my /DMYOTHERSYMBOL=\"someOtherString\" string\"

input : /DMYSYMBOL="""my string""" /DMYOTHERSYMBOL="""someOtherString"""
output: /DMYSYMBOL="""my /DMYOTHERSYMBOL="""someOtherString""" string"""


Is there a way to do this? Or should I follow a whole different approach altogether to get the environment variable in?

0 answers