0

I've got a little bit untidy project in C++ (Visual Studio solution + CMakeLists.txt). There is a lot of "includes" from an external projects, and it is hard to say, which one are really in use.

I want to remove all unused headers, and related to them implementation files from both Visual Studio solution and CMakeLists.txt.

Is there any tool for such a task?

Dejwi
  • 4,393
  • 12
  • 45
  • 74
  • Probably duplicate of: http://stackoverflow.com/questions/74326/how-should-i-detect-unnecessary-include-files-in-a-large-c-project. Now also Resharper c++ can do that. – Nikolay Jul 21 '15 at 08:42

1 Answers1

1

A commercial solution for this problem is "Understand for C/C++". It's an application that scans your complete codebase, stores all relations in an internal database, after which you can open all kinds of reports or perform queries on it. I think it has the possibility to also look for unused classes, unused methods, dead code, ...

A free solution might be to use the /VERBOSE linker option of Visual Studio. This option causes the linker to print out all object files that are included in the final executable. You can take this output, match this with all of your .CPP files, and then see which .CPP files are not included in the executable (this might require you to write a small utility, or maybe some Excel magic).

Patrick
  • 23,217
  • 12
  • 67
  • 130