Powering `clangd`-based C++ IDEs with `compile_commands.json`
What is compile_commands.json?
clangd
, the C++ language server that powers IDE features in VS Code, CLion, etc. such as code navigation, linting and error detection, and refactoring, requires compile_commands.json
, a JSON file that records exactly how each source file in your project should be compiled. The example shows a simple structure:
1 |
|
Each entry contains:
directory
: The absolute path of where the compilation occurscommand
: The full compilation command (Shell features such as variable and command substitution are NOT supported)file
: The relative path of the source file being compiled
Generating compile_commands.json
You can create one manually as shown in the following Shell script:
1 |
|
This approach works well for small projects. For larger ones, consider using CMake or bear
(for make-based projects).
Powering `clangd`-based C++ IDEs with `compile_commands.json`
https://jifengwu2k.github.io/2025/08/11/Powering-clangd-based-C-IDEs-with-compile-commands-json/