-1

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?

Ramin B
  • 35
  • 5
  • https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors – 463035818_is_not_an_ai Dec 13 '22 at 16:36
  • 2
    I would just move the project in your file explorer and not use macros. If you have to adjust paths the visual studio project files are text and basically xml. You could do a search and replace on them. – drescherjm Dec 13 '22 at 16:37
  • May I ask why you prefer not to use macros? Will I face some problems down the road? Because this relocation of the **commonFolder** is an obligation for us. – Ramin B Dec 13 '22 at 16:51
  • I don't think macros make the problem any easier and in c++ macro usage should be very limited. – drescherjm Dec 13 '22 at 16:53
  • Related: [https://stackoverflow.com/questions/266501/macro-definition-containing-include-directive](https://stackoverflow.com/questions/266501/macro-definition-containing-include-directive) – drescherjm Dec 13 '22 at 16:55
  • Also: [https://stackoverflow.com/questions/30465646/expand-define-macro-with-include-macro](https://stackoverflow.com/questions/30465646/expand-define-macro-with-include-macro) – drescherjm Dec 13 '22 at 16:56
  • I am quite new to the subject so my question might sound easy. But , isn't there another way to create relative path other than using macros? Thanks – Ramin B Dec 13 '22 at 17:00
  • You can add an `Additional Include Directory` to any of your projects using a relative path to that project. Perhaps `../../SharedFolder/CommonFolder` – drescherjm Dec 13 '22 at 17:05
  • I did the change that you said using the relative path , but I am still getting the error of : 'cannot open include file: 'fileName' : No such file or directory' . This is while I have changed all the required directory settings in the *.vcxproj file , and also the fact that the not-found file is in the directory. I also checked the properties of the project in Visual Studio. I know there are different reasons why we get this error , but I think in my case it's strictly related to the **include directory**. Any Idea on this? You've been helpful and thanks for that. – Ramin B Dec 13 '22 at 17:30
  • Did you change it in all configurations? Remember the settings in Visual Studio are independent for each configuration: Release, Debug ... – drescherjm Dec 13 '22 at 17:33
  • yes. But the only thing that is needed to be changed is **Additional Include Directory** inside the *.vcxproj file. Because that's where the project reads the files from. So basically there are two folders that this project is reading the data from. I write the directories as I wrote in my configurations : **src;../trunk/Externals/common** src works perfectly since it is inside the project folder. But common folder is not inside the project folder and is in a parent folder. – Ramin B Dec 13 '22 at 17:46
  • Was your problem solved? – Minxin Yu - MSFT Dec 16 '22 at 09:42

1 Answers1

0

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"

Minxin Yu - MSFT
  • 2,234
  • 1
  • 3
  • 14