How to include sub-directories in Visual Studio?

后端 未结 4 1825
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 05:06

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

4条回答
  •  醉话见心
    2021-02-04 05:29

    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.

提交回复
热议问题