C++ – How to include sub-directories in Visual Studio


I have to include many header files, which are in different sub-directories. Is there a way in Visual Studio (I am using 2005 edition) to set one include path that Visual Studio will search also the sub-directories for header files?

Best Solution

Setting the folder search paths in the Visual Studio settings to fix an include issue is generally not really a good idea from a design point of view. Your code will be less portable to different machines with different directory lay-outs.

My suggestion would be to settle on an organisation of your code so that the relative paths of the sub-directories (relative to your including code) are fixed:

  • Add the "base folder" to the project (project properties -> Configuration Properties -> C/C++ -> Additional Include Directories, "additional include directories")
  • Add the subdirectories to the #include statements , i.e. #include "subdirectory/somefile.h".

This has the added bonus of being able to see which folder in your Solution contains the file - that is often useful information when you're trying to find your way around or trying to figure out what a file is for.