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?
Go to your Control Panel in Windows, click on Programs and then on Programs and Features. You'll see a list of everything that's installed on your machine. Go through that list, and ask yourself: do I *really* need this program? If the answer is no, hit the Uninstall/Change button and get rid of it.
An easy way to do this is to press Windows key + S to activate the search bar, type cleanup , and then click Disk Cleanup in the search results. Disk Cleanup is one of the fastest ways to delete unneeded files created by the Windows operating system.
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.
PC Lint works quite well for this, and it finds all sorts of other goofy problems for you too. It has command line options that can be used to create External Tools in Visual Studio, but I've found that the Visual Lint addin is easier to work with. Even the free version of Visual Lint helps. But give PC-Lint a shot. Configuring it so it doesn't give you too many warnings takes a bit of time, but you'll be amazed at what it turns up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With