.clangd:根据文件扩展名使用不同的编译器标志

Gab*_*ers 4 c c++ configuration compiler-flags clangd

我正在使用.clangd配置文件将编译标志传递给 clangd。

我在包含 C 和 C++ 文件的代码库上运行 clangd。

如何让一些标志应用于 C++ 文件而不是 C 文件?

Gab*_*ers 5

您可以使用多个片段和If块语法。

例子:

# Fragment common to C and C++ source files
CompileFlags:
    Add:
        - "--include-directory=some/directory/to/search/includes/in"
        - "-D"
        - "SOME_MACRO_TO_DEFINE"
        - "-include"
        - "some/file/to/force/inclusion/of.h"

---
# Fragment specific to C++ source files
If:
    PathExclude: [.*\.c, .*\.h]
CompileFlags:
    Add:
        - "-std=c++17"
Run Code Online (Sandbox Code Playgroud)

---分隔片段。

PathMatch可能比PathExclude依赖代码库中的扩展更实用。

我在 clangd 13.0.0 上对此进行了测试。

我从这个 Github 问题中得到了帮助。

更多帮助请参阅clangd 官方文档