Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access $(SolutionDir) macro from C++ code

How to access the $(SolutionDir) macro from C++ code. Simply I want to get the solution directory path as a string. So that I can setup my project in any computer and get the sln directory path accordingly.

like image 752
Zarco Avatar asked Nov 14 '13 04:11

Zarco


2 Answers

I have the same issue some time ago (I will note down vote but there is no really answer here).

What I did was also define Preprocesor macro and with c++11 one can easily escape the problem of escapes characters. To do that go into

Properties → Configuration Properties → C/C++ → Preprocessor

There is field PreprocessorDefinitions so you need to add there:

SOLUTION_DIR=R"($(SolutionDir))"

To explain the R"()" stands for c++ string literal so there will be no problem with escape characters (they are available since C++11).

From my use case this works perfectly in Visual Studio 2015 and 2017 (should also work in 2013 and 2012. In 2010 and before there was no support for Raw String)

like image 181
wdudzik Avatar answered Oct 09 '22 14:10

wdudzik


I solved this. Here using the $(SolutionDir) is giving the solution directory path. But there is a problem when it takes as a string because of return statement of $(SolutionDir) contains the path including slashes () without escape character. Ex: C:\TestApp\ But to use as string it should be C:\TestApp\ Perhaps it can be used internally when setting the properties.

like image 35
Zarco Avatar answered Oct 09 '22 13:10

Zarco