如何在Visual Studio中包括子目录? [英] How to include sub-directories in Visual Studio?
问题描述
我必须包含许多头文件,这些头文件位于不同的子目录中.在Visual Studio(我使用的是2005版)中,有没有一种方法可以设置一个包含路径,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?
推荐答案
在Visual Studio设置中设置文件夹搜索路径以解决包含问题通常不是一个好主意.您的代码将难以移植到具有不同目录布局的其他计算机上.
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:
- 将基本文件夹"添加到项目中(项目属性->配置属性-> C/C ++->其他包含目录,其他包含目录" )
- 将子目录添加到#include语句中,即
#include "subdirectory/somefile.h"
.
- 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.
这篇关于如何在Visual Studio中包括子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!