简体   繁体   中英

Additional include directories in Visual Studio for C++

I have a folder structure like this:

mother directory/Solution A/Project Aa/ file Aaa.h

mother directory/Solution B/Project Bb/ file Bbb.h

I would like to include Aaa.h in Bbb.h.

The Bbb.h looks like this:

#include <A/Aa/Aaa.h>

...

In the properties of the project Bb, I have tried C++ -> General -> Additional include directories: $(ProjectDir)../../../

Or I also tried../../../ or $(ProjectDir)../../..

Nothing works. I get the error message: "cannot open source file "A/Aa/Aaa.h".

How can I include the "Aaa.h" correctly into Bbb.h?

Your problem is that the "A" directory is not inside the "B" directory, and the line #include <A/Aa/Aaa.h> looks for the path you gave starting from the current directory , so it's looking for: "B/Bb/A/Aa/Aaa.h" To resolve this, you can do one of two things.

  1. Indicate the actual location of the Aaa.h (relative to Bbb.h) file in the include statement: #include "../../A/Aa/Aaa.h>" (Using such relative paths, however, will generate warnings in many compilers, as they aren't really portable.)
  2. Add the directory (again, relative to the project) in the list of include folders as "../../A/Aa" and then just give the filename in the include line: #include "Aaa.h" (To avoid any confusion with typing in the directory path, you can just 'browse' for the actual folder from the "Properties" pop-up.)

PS: Though not strictly enforced, the custom is to use the < > 'quotes' for header files in system directories (like #include <iostream> ) and traditional quotes for user-supplied headers (like #include "Bbb.h" ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM