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

发布于 2025-01-14 03:39:38 字数 113 浏览 4 评论 0原文

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

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

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

I am using the .clangd configuration file to pass compilation flags to clangd.

I run clangd on a codebase with C and C++ files.

How can I have some flags apply to C++ files but not C files ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫瑟鸿黎 2025-01-21 03:39:38

您可以使用多个片段和 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"

--- 分隔片段。

PathMatch 可能比 PathExclude 更实用,具体取决于代码库中的扩展。

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

我从此 Github 问题获得了帮助。

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

You can use multiple fragments and the If block syntax.

Example:

# 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"

--- delimits fragments.

PathMatch could be more practical than PathExclude depending on the extensions in your codebase.

I tested this on clangd 13.0.0.

I got help from this Github issue.

More help in clangd official documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文