LinuxCommandLibrary

cppclean

C++ unused header and code finder

TLDR

Find unused includes in a directory
$ cppclean [path/to/source]
copy
Check specific files
$ cppclean [file1.cpp] [file2.cpp]
copy
Include additional paths
$ cppclean --include-path [/path/to/includes] [source/]
copy

SYNOPSIS

cppclean [options] paths...

DESCRIPTION

cppclean finds problems in C++ source that slow development and increase compilation time. It detects unused #include directives, unnecessary headers, and other issues that bloat build times without contributing to functionality.
The tool analyzes code to identify which headers can be safely removed, reducing compilation dependencies and speeding up incremental builds. It also finds forward declarations that could replace full includes, further optimizing compile times.
By cleaning up unused includes and identifying unnecessary dependencies, cppclean helps maintain lean, efficient C++ codebases and improves developer productivity through faster build cycles.

PARAMETERS

--include-path path

Additional include search paths.
--exclude pattern
Exclude files matching pattern.

CAVEATS

May report false positives for conditionally compiled code. Results should be verified before removing includes.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard