MSVC use additional include directories of referenced static library project

250 Views Asked by At

I have two projects in my C++ MSVC solution:

  1. A static library project

  2. A .exe project that has a reference to the Project #1 (the static library project)

  • Project #1 has additional include directories, C:/addincdir .
  • Project #1's header file, p1header.h includes the header hd.h from C:/addincdir.
  • Project #2 includes p1header.h .

But when I build the solution, I get an error: Project #2 cannot open include file hd.h (cannot find/locate the header file.) I know the solution is to add C:/addincdir to Project #2's additional include directories.

But is there a way for MSVC to automatically add referenced project's additional include directories? Or is there some kind of macro like $(Project1additionalincludedirectories) that includes Project #1's additional include directories and I can add this variable to Project #2's additional include directories?

It just wouldn't be practical to copy-paste every additional include directory from Project #1 to Project #2.

2

There are 2 best solutions below

3
On BEST ANSWER

No. There is no way to automatically add the folders.

(step 5 in Walkthrough: Create and use a static library - Use the functionality from the static library in the app)

To include a header file (listed in the additional include folders) you need to use <... >

#include <header.h++>
0
On

You can use an environmental variable such as using MORE_INC_DIR and set it to C:/addincdir1;C:/addincdir2;C:/addincdir3; and put $(MORE_INC_DIR) in the additional include directories of both projects.