jjcasmar
jjcasmar

Reputation: 1675

clangd for vscode with multiple build directories

I am trying to use clangd for code completion within vscode. I am using CMake for the project setup and I am creating a compilation database. However, I have several build directories with different flags (Debug, Release...) and clangd requires to have the compilation database in the source directory. This is not possible, since compilation databases for each build type are different...

Is there any way to use clangd when you have multiple build types?

Upvotes: 3

Views: 4156

Answers (2)

jjcasmar
jjcasmar

Reputation: 1675

I solved this my using a VSCode cmake tools feature.

in the settings of my workspace I added

    "cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json"

This copies the compile_commands.json of the build dir to workspace folder, which in my case happens to be where clangd is looking for the compile_commands.json file.

If I change the preset, the new compile_commands.json from the new is copied again so the clangd model is updated.

Upvotes: 8

Tanuva
Tanuva

Reputation: 151

I typically solve this by symlinking one compilation database into the source directory. Which one depends on what I do - mostly it is the one for the "standard" build I use most often. There are other specialized builds, but I only switch to the corresponding compdb if I really need the different settings.

Upvotes: 0

Related Questions