I create a little tool to check self contained headers and redundant #include in C++ code

https://github.com/wqking/cpp-header-checker

cpp-header-checker is a tool that can check C++ source file that
1. If a C++ header file is self contained. If a header is self contained, it can be included without any other header files.
2. If a C++ file has redundant `#include`. Redundant `#include` means if the include is removed, the file can be compiled without errors.

The tool is written in Python 3, tested with Python 3.8.10.

I've used this tool in my eventpp library (https://github.com/wqking/eventpp) and fixed several header related problems.

## Features

- Check if header files are self contained.
- Check if any `#include` is redundant and can be removed.
- Utilize multi-threading. The check is pretty fast.
- Not intrusive. The tool doesn't modify the source files.
- Support checking multiple files.
- Support checking files recursively in nested folders.

## License

Apache License, Version 2.0

## Examples

Below command can check if the headers are self contained in eventpp

 
python cpp-header-checker.py complete --source EVENTPP_FOLDER/include/**/*.h --temp ./temp --command "gcc {file} -c -o {file}.o -IEVENTPP_FOLDER/include" --exclude _i.h


Below command can check if any `#include` is redundant in eventpp

 
python cpp-header-checker.py redundant --source EVENTPP_FOLDER/include/**/*.h --temp ./temp --command "gcc {file} -c -o {file}.o -IEVENTPP_FOLDER/include" --exclude _i.h


I created another little tool to add license header to source file, which works quite well for C++. https://github.com/wqking/license-header

Let me know your opinions
Last edited on
Topic archived. No new replies allowed.