0

How can I read one of VS project environment variables oder user-defined macros such as the ${SolutionPath} from source code in C++?

I just created a new user-defined macro where I want to store the current Version of my project. I want to use this value during build as well as to show it in the GUI. Do you have any better idea to have only one place to store the current version of my product?

It seems like defining additional preprocessor flags for each project using /D might by a solution, but I cannot get it to work to define a precompiler flag with a value.

1 Answer 1

1

You can add an additional compiler option using the following format

/D "VariableName=\"VariableValue\""

This will make the macro available in the project just as if you typed:

\#define VariableName VariableValue
Sign up to request clarification or add additional context in comments.

1 Comment

This is clever but what about directory names that contain backslashes? How to get the preprocessor to interpret them literally?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.