Compilation database compile_commands.json

A compilation database is a JSON-formatted file named compile_commands.json that contains structured data about every compilation unit in your project.

PlatformIO Core (CLI) supports generating of compilation database using pio run --target command and compiledb target. For example,

> pio run -t compiledb

A default path for compile_commands.json is “build_dir/envname”. You can override this path with Advanced Scripting and COMPILATIONDB_PATH environment variable. For example, generate compile_commands.json in a root of project:


platform = ...
board = ...
extra_scripts =

import os

env.Replace(COMPILATIONDB_PATH=os.path.join("$PROJECT_DIR", "compile_commands.json"))