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?
C++ – How should I detect unnecessary #include files in a large C++ project
cdependenciesheaderincludevisual-studio-2008
Related Topic
- Javascript – How to include a JavaScript file in another JavaScript file
- C++ – Displaying the #include hierarchy for a C++ file in Visual Studio
- Java – How to add local jar files to a Maven project
- C++ – Why is this program erroneously rejected by three C++ compilers
- Javascript – In Node.js, how to “include” functions from the other files
- C++ – Is std::unique_ptr
required to know the full definition of T - C# – System.Windows.Application.GetResourceStream returns null
Best Answer
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.