I’m posting this info on how to set up extra include paths and edit linked files in Visual Studio for my own reference.
This was originally acquired from here on October 10, 2010.
Settings for compiler
In the project where you want to #include the header file from another project, you will need to add the path of the header file into the Additional Include Directories section in the project configuration.
To access the project configuration:
- Right-click on the project, and select Properties.
- Select Configuration Properties->C/C++->General.
- Set the path under Additional Include Directories.
How to include
To include the header file, simply write the following in your code:
1 |
#include "filename.h" |
Note that you don’t need to specify the path here, because you include the directory in the Additional Include Directories already, so Visual Studio will know where to look for it.
If you don’t want to add every header file location in the project settings, you could just include a directory up to a point, and then #include relative to that point:
1 2 3 4 5 |
// In project settings // Additional Include Directories ..\..\libroot // In code #include "lib1/lib1.h" // path is relative to libroot #include "lib2/lib2.h" // path is relative to libroot |
Setting for linker
If using static libraries (i.e. .lib file), you will also need to add the library to the linker input, so that at linkage time the symbols can be linked against (otherwise you’ll get an unresolved symbol):
- Right-click on the project, and select Properties.
- Select Configuration Properties->Linker->Input
- Enter the library under Additional Dependencies.