Search code examples
c++visual-studiodirectorymacrosrelative-path

Defining relative path using macro


I am refactoring a code project (written in both c++ and c#) in visual studio and the structure of my directory is roughly like the attached picture here : enter image description here

P.s project2.sln is a part of a big project in the same directory.

Inside the commonFolder there are some .h and .cpp files that are used by the project2.sln located in folder 2.

I want to move this commonFolder to the SharedFolder and instead of giving an absolute path, I would like to give relative path (using Macros) to the properties of project2.sln so it can be compiled for all the users that checkout this trunk folder.

How can i define this relative path for the commonFolder using Macros?


Solution

  • Additional Include Directory is the convenient way to give relative path.

    As an alternative, you can use shared item project.

    These “shared items” projects don’t participate in build but they can contain any number of C++ headers and sources.

    1. move .h and .cpp files to shared item project folder.
    2. add existing item in shared item project
    3. add references in the project2

    enter image description here enter image description here

    1. find the places where the error: cannot open the file. Modify path:

    For example: #include "E:XXX/folder2/commonFolder/test.h" to #include "test.h"