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?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- How to know full paths to DLL's from .csproj f
- Importing NuGet references through a local project
相关文章
- How to show location of errors, references to memb
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- How to track MongoDB requests from a console appli
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
I believe using recursive search for include files would cause so much more problems than it solves in a form of wrong files or wrong versions being included. After all, you have to define the right directories once when you set up the project.
We haven't found a way of setting a recursive folder search in Visual Studio (though Xcode has no problem setting and using them). What we do is list all the directories in a file, and specify the file in the C/C++ Command Line additional options:
@"IncludeFolders.rsp"
We rarely find problems using recursive search, though an accidental inclusion of ``/'' did slow things down a bit once.
I've found that I can shorten path lengths in most situations, including in MSVC, by a slight of hand trick using the SUBST command. I'll show and example for shortening the default inherited C++ include paths, but you would do this for your project related include paths. First create one or more batch files like this (and run them from Windows Explorer or the command line):
You can create a number of these for your longer paths. In the case above I am only shortening the standard inherited paths that MSVC uses by default. BTW, the Subst command works w/o administrative rights, but don't step on an existing physical or mapped drive letter (I'm not sure what would happen--I don't want to test it at the moment).
This step is optional. I in MSVS 2010+ I add a custom properties sheet. BTW, if you don't know about custom properties sheets you should. See Property Pages (Visual C++). VIEW-Other Windows-Property Window, right click the project in the Property manager, Add a New Project Properties Sheet. Under User Macros, add a Macro, e.g. MyProjectIncludePaths and set the value (in this example) to
--only 49 characters in this example, which is much shorter than the default of
which upon macro expansion translates to
By my count the default is 270 characters--i.e. longer than 260 characters--can anyone explain this?
In the Property Pages for the project (i.e. not the custom property sheet), in my example I went to Configuration Properties-VC++ Directories and changed the Include Directories value to $(MyProjectIncludePaths), but in practice it you would go to (in your custom property sheet page if you created one) C/C++-General and add $(MyProjectIncludePaths) to the Additional Include Directories.
In addition to the inherited 270 character paths, I have been able to add a few reasonable length paths under Additional Include Directories. Maybe the Additional Include Directories has its own length limit (?).
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:
#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.