Include What You Use – source analysis tool

Include What You Use (IWYU) is a source analysis tool for C and C++ projects built on Clang. It examines header dependencies to determine whether source files directly include the declarations required by the symbols they use.

In large C and C++ projects, header dependencies can become difficult to maintain. Files may rely on declarations included indirectly through unrelated headers, while retaining other includes that are no longer necessary. IWYU identifies these relationships and recommends changes that make individual source files more self-contained.

The tool can analyse individual translation units or integrate with existing build workflows. It also supports compilation databases, allowing developers to examine entire projects using their normal compiler options.

IWYU provides recommendations for adding and removing includes, replacing suitable dependencies with forward declarations and cleaning up existing include directives. Developers should review its suggestions carefully, particularly in projects with unusual header structures or complex library dependencies.

This is free and open source software.

Key Features

  • Analyses C and C++ source files to identify missing, unnecessary and indirect header dependencies.
  • Recommends direct includes for symbols used by individual translation units.
  • Identifies header dependencies that can be replaced with forward declarations.
  • Provides separate recommendations for source files and their associated headers.
  • Supports analysis of additional header files through configurable file patterns.
  • Integrates with existing build systems using normal compiler options.
  • Works with CMake through its native Include What You Use integration.
  • Processes compilation databases using the iwyu_tool.py helper script.
  • Includes fix_includes.py for applying suggested include changes automatically.
  • Customisable handling of include comments and forward declarations.
  • Supports IWYU pragmas to preserve includes, mark private headers and control dependency analysis.
  • Custom header mappings help associate private declarations with their public headers.
  • Compatible with Clang-based source analysis workflows.
  • Cross-platform support – runs on Linux, macOS, and Windows.

Website: github.com/include-what-you-use/include-what-you-use
Support:
Developer: include-what-you-use contributors
License: University of Illinois/NCSA Open Source License

Include What You Use is written in C++. Learn C++ with our recommended free books and free tutorials.


Related Software

C and C++ Linters
OCLintStatic code analysis tool for improving quality and reducing defects
cpplintStatic code checker for C++
CodeCheckerPlatform for running static analysers and managing code defects
UncrustifySource code beautifer
InferStatic analyser that detects bugs in Java, C and C++ code
Include What You UseSource analysis tool for C and C++ projects built on Clang
CppcheckStatic analysis tool for C/C++ code
flawfinderScans C and C++ source code for potential security weaknesses
clazyQt-focused static analyser that catches common C++ mistakes
ClangFormatCode formatting tool
Clang-TidyClang-based C++ “linter” tool
SmatchStatic analysis tool for finding defects in C code
CoccinelleSemantic patching tool for analysing and transforming C code

Read our verdict in the software roundup.


Best Free and Open Source Software LinuxLinks helps you discover the best free and open source software for Linux. Explore our extensive collection of recommended applications, including alternatives to popular proprietary software.

We also publish software reviews, Linux tutorials, hardware reviews, free programming books and articles covering the wider open source community. Browse our Linux resources to discover more.

Know a useful free and open source Linux application we haven't covered? Suggest a program for inclusion.

Has your software been featured on LinuxLinks? Display one of our Featured on LinuxLinks badges on your website or GitHub README.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted