Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Visual Studio throws "undeclared identifier" from predefined string macro

I have the following preprocessed macro defined under C/C++ -> Command Line -> Additional Options:

/D NV_WORKING_DIRECTORY="C:/foo" 

An image from the project settings:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have the following code:

std::string path = NV_WORKING_DIRECTORY;

When I compile I get this error:

‘C’: undeclared identifier.

Weirdly, with certain strings the code works. For example if I do /D NV_WORKING_DIRECTORY="foo" everything is good. But "garbage" for some reason gives the same error.

Hardcoding#define NV_WORKING_DIRECTORY "C:/foo/" makes the code above work, but because I need a global macro that is not an option.

Is there something I am doing wrong here? This is a brand new project, and I have not messed around with anything yet.

>Solution :

When you use /D in the C/C++ -> Command Line -> Additional Options, the value is expected to be wrapped in a string.
E.g. the following means the value of XXX will be YYY:

/D XXX="YYY"

Therefore if you need the value of the preprocessor definition to contain the quotes, you need to add and escape them:

/D NV_WORKING_DIRECTORY="\"C:/foo/\""

Alternatively you can add the NV_WORKING_DIRECTORY defintion under C/C++ -> Preprocessor Definitions.
There you can simply put the string value that you need:

NV_WORKING_DIRECTORY="C:/foo/"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading