Setting up include-what-you-need (IWYU)

Use following instructions to install IWYU ( on Ubuntu 18.04.3 LTS:

sudo apt-get update
sudo apt-get install -y build-essential cmake git zlib1g-dev libncurses5-dev llvm-6.0-dev libclang-6.0-dev libclang-6.0-dev clang-6.0
git clone iwyu.git
cd iwyu.git
git checkout clang_6.0
mkdir -p build
cd build
cmake -DIWYU_LLVM_ROOT_PATH=/usr/lib/llvm-6.0 ..
make install

Once installation is complete, you will find `include-what-you-need`

# include-what-you-use --version
include-what-you-use 0.10 (git:a1878c4) based on clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)

To execute include-what-you-need:

Build your cpp project with cmake and pass on an extra parameter `-DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE` to cmake. It will produce  `compile_commands.json` file in your build folder for the project.

  • Execute ` -p </path/to/folder/having/compile_command.json>`. It may take time depending upon the code size.
  • `fix_includes` can be used to apply recommended changes.

To use it in VSCode add following to the `tasks.json`

    "label": "CXX Analysis -- iwyu",
    "detail": "Run IWYU tool for CPP project",
    "command": "",
    "args": [
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": true,
        "panel": "shared",
        "showReuseMessage": true,
        "clear": false
    "problemMatcher": "$gcc"


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s