How to use clangd with multiple projects?

How can I use clangd in a workspace setup that consists of multiple cmake projects which compile into a common build location?

My workspace consists of several projects, with a structure roughly like this:

workspace/src/project_1/src/file_1.cpp
workspace/src/project_1/include/project_1/file_1.h

workspace/src/project_n/src/file_n.cpp
workspace/src/project_n/include/project_n/file_n.h

The build output then happens somewhere else, and a separate compile_commands.json is produced for each cmake project:

workspace/build/project_1/compile_commands.json

workspace/build/project_n/compile_commands.json

How can I get clangd to use all the compile_commands.json files? Do I have to link them separately to the root of each project?

Do I have to link them separately to the root of each project?

That’s the only way I’m aware of currently.

We do have Allow the client to specify multiple compilation databases · Issue #116 · clangd/clangd · GitHub on file for adding a mechanism to specify multiple compilation database files explicitly.

1 Like