I am working on a large C++ project in Visual Studio 2008, and there are a lot of files with unnecessary #include
directives. Sometimes the #include
s are just artifacts and everything will compile fine with them removed, and in other cases classes could be forward declared and the #include could be moved to the .cpp
file. Are there any good tools for detecting both of these cases?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- How to add external file to application files ( cl
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
While it won't reveal unneeded include files, Visual studio has a setting
/showIncludes
(right click on a.cpp
file,Properties->C/C++->Advanced
) that will output a tree of all included files at compile time. This can help in identifying files that shouldn't need to be included.You can also take a look at the pimpl idiom to let you get away with fewer header file dependencies to make it easier to see the cruft that you can remove.
If you would work with Eclipse CDT you could try out http://includator.com to optimize your include structure. However, Includator might not know enough about VC++'s predefined includes and setting up CDT to use VC++ with correct includes is not built into CDT yet.
Adding one or both of the following #defines will exclude often unnecessary header files and may substantially improve compile times especially if the code that is not using Windows API functions.
See http://support.microsoft.com/kb/166474
If your header files generally start with
(as opposed to using #pragma once) you could change that to:
And since the compiler outputs the name of the cpp file being compiled, that would let you know at least which cpp file is causing the header to be brought in multiple times.
The latest Jetbrains IDE, CLion, automatically shows (in gray) the includes that are not used in the current file.
It is also possible to have the list of all the unused includes (and also functions, methods, etc...) from the IDE.
There's a new Clang-based tool, include-what-you-use, that aims to do this.