How to use cppclean to find unused headers

I'm looking for a tool to help me find an unnecessary header contained in a large C ++ codebase. Other stackoverflow questions on this topic all suggest cppclean. So I installed cppclean and I am trying to use it, but even with trivially incorrect examples, it does not give any results.

For example, this is what I am trying to clean up. Original file:

// foo.cpp
#include "bar.h"

void main() { };

      

And the header file:

// bar.h
class bar {
};

      

And I ran:

cppclean foo.cpp

      

But it doesn't print anything and returns 0.

Am I doing something wrong? Are there any guides for using this tool?

+3


source to share


2 answers


Run cppclean .

inside the working directory where your cpp and header files are. You must provide all your source code to Cppclean so that it can parse them and look for problems.



To include multiple directories, see the Run section of the Cppclean documentation .

0


source


The cppclean documentation clearly states that right on the first page under the Features section:

  • Find and print C ++ language constructs: classes, methods, functions, etc.
  • Find classes with virtual methods, no virtual destructor and no reason
  • Find global / static data that are potential problems when using streams
  • Unnecessary direct class declarations
  • Declaring unnecessary functions
  • Undeclared function definitions
  • (planned) Find unnecessary #include header files
    • There is no direct link to anything in the title
    • No header needed if classes were declared instead
  • (planned) Source files that reference headers that do not directly contain #, i.e. files that rely on> transitive #include from another header
  • (planned) Unused members (private, protected and public) methods and data
  • (planned) Save AST in SQL database so relations can be queried


Planned means this is a feature they plan to add in the future. That's not all.

-3


source







All Articles