0

On Visual Studio I see one can set path of i.e. util\util.h on that side panel, right-click the project then

Properties > C/C++ > General > ...

I add util directory there and then I can do #include "util.h" on a file from another directory, instead of providing the full path util\util.h.

Besides the approach descrived, is there another way which also will allow me to #include "util.h" (not provide the full path)?

I'm not familiar with Visual Studio at all.

KcFnMi
  • 5,516
  • 10
  • 62
  • 136
  • Probably [this](https://stackoverflow.com/questions/335408/where-does-visual-studio-look-for-c-header-files) answers your question? – SelfishCrawler Dec 11 '20 at 11:12

2 Answers2

0

Within the the Visual Studio Dialog you describe under: Properties > C/C++ > General > if you select the drop down icon and select "Edit" you will see a button titled "Macros" this provides a list of available Macros for use on the "Additional Include Directories" line. Likely you will want to use: "$(ProjectDir)\util". $(ProjectDir) is the directory that your project file is sitting in.

Jeff Spencer
  • 507
  • 2
  • 11
  • It wasn't clear to me, since she also asked not to have to provide the full path. But being new to Visual Studio I suspect she isn't aware of the macros – Jeff Spencer Dec 11 '20 at 21:03
0
  • Let say you have created a project names 'Project1'. Then there will be a 'Project1.vcxproj' file which stores the settings for the project. Visual studio also looks for any files (source or header) in the folder starting with where this project file is located. Use the relative path with respect to where this file is located.

Let say your directory structure is as follows:

-Project\
--Project1\
---Project1.vcxproj
-Source\
--header.h

Use include path as 
#include "..\Source\header.h"
TKA
  • 183
  • 2
  • 4