Here are some examples of how to setup clangd for a project
meson setup <build_dir>
generates a compilation database in <build_dir>/compile_commands.json
. Since clangd
automatically looks for the compilation database in build
, we don't need to do anything else if build
is the name of the build directory
meson setup build
If we want to use a custom build directory (eg. meson setup builddir
), we can add a new file .clangd
to the root of the directory to specify the path to the compilation database
CompileFlags:
CompilationDatabase: builddir
Or just symlink the compilation database to the root of the directory
ln -s builddir/compile_commands.json .
ninja -t compdb > compile_commands.json
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1
Use bear
bear -- make
If the project does not use any of the above (eg. it is a rust sys crate containing some header files), we can still setup clangd
manually using a configuration file. This can be done per project (/path/to/project/.clangd
) or per OS user (~/.config/clangd/config.yaml
)
CompileFlags:
Add:
- -I/usr/include/lib1
- -I/usr/include/lib2
- ...