最后在setting.json中设置json文件的路径 {"cmake.buildDirectory":"${workspaceFolder}/out","clangd.arguments":["-background-index","-compile-commands-dir=out/build/x64-Debug"],} 参考: