Clangd无法解析STL Lib标题

发布于 2025-02-06 10:29:48 字数 1869 浏览 1 评论 0 原文

当我配置Neovim LSP时,我遇到了一个问题。我的LSP客户端是NVIM-LSPConfig,Clangd是我的LSP服务器。 这是我的clangd设置参数

require('lspconfig')['clangd'].setup {
  on_attach = on_attach,
  flags = {
    -- This will be the default in neovim 0.7+
    debounce_text_changes = 150,
  },
  capabilities = capabilities,
  cmd = {
    'clangd',
    '--background-index',
    '--query-driver="/app/vbuild/RHEL7-x86_64/clang/latest/bin/clang, \
                     /app/vbuild/RHEL7-x86_64/clang/latest/bin/clang++, \
                     /app/vbuild/RHEL7-x86_64/gcc/latest/bin/gcc, \
                     /app/vbuild/RHEL7-x86_64/gcc/latest/bin/g++"',
    '--clang-tidy',
    '--all-scopes-completion',
    '--cross-file-rename',
    '--completion-style=detailed',
    '--header-insertion-decorators',
    '--header-insertion=iwyu',
    '--pch-storage=memory',
    '--enable-config',
    '--log=verbose'
  },
  filetypes = {"c", "cpp", "objc", "objcpp"}
}

,我的G ++和clangd版本同时同时

g++ (GCC) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

clangd version 14.0.0
Features: linux
Platform: x86_64-unknown-linux-gnu

,我将以下路径添加到我的CPATH中,

setenv CPATH "/app/vbuild/RHEL7-x86_64/gcc/latest/include/c++/10.3.0:/app/vbuild/RHEL7-x86_64/glibc/2.33/include"
setenv CPATH "/app/vbuild/RHEL7-x86_64/clang/latest/include/clang-c:/app/vbuild/RHEL7-x86_64/clang/latest/include/llvm-c:$CPATH"

但我仍然在Neovim

输入图像说明在这里

似乎Clangd找不到相关的STL标题。但是我检查了$ cpath中的路径。它确实具有STL标题。有人知道如何解决这个问题吗? 谢谢

I met a issue when I config my neovim lsp. My lsp client is nvim-lspconfig and clangd is my lsp server.
Here is my clangd setup arguments

require('lspconfig')['clangd'].setup {
  on_attach = on_attach,
  flags = {
    -- This will be the default in neovim 0.7+
    debounce_text_changes = 150,
  },
  capabilities = capabilities,
  cmd = {
    'clangd',
    '--background-index',
    '--query-driver="/app/vbuild/RHEL7-x86_64/clang/latest/bin/clang, \
                     /app/vbuild/RHEL7-x86_64/clang/latest/bin/clang++, \
                     /app/vbuild/RHEL7-x86_64/gcc/latest/bin/gcc, \
                     /app/vbuild/RHEL7-x86_64/gcc/latest/bin/g++"',
    '--clang-tidy',
    '--all-scopes-completion',
    '--cross-file-rename',
    '--completion-style=detailed',
    '--header-insertion-decorators',
    '--header-insertion=iwyu',
    '--pch-storage=memory',
    '--enable-config',
    '--log=verbose'
  },
  filetypes = {"c", "cpp", "objc", "objcpp"}
}

And my g++ and clangd version as follow

g++ (GCC) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

clangd version 14.0.0
Features: linux
Platform: x86_64-unknown-linux-gnu

At the same time, I add the following include path into my CPATH

setenv CPATH "/app/vbuild/RHEL7-x86_64/gcc/latest/include/c++/10.3.0:/app/vbuild/RHEL7-x86_64/glibc/2.33/include"
setenv CPATH "/app/vbuild/RHEL7-x86_64/clang/latest/include/clang-c:/app/vbuild/RHEL7-x86_64/clang/latest/include/llvm-c:$CPATH"

But I still found these errors in my neovim

enter image description here

enter image description here

It seems like clangd cannot find related stl headers. But I checked my include path in $CPATH. It indeed has stl headers. Does anyone know how to fix this issue?
Thanks

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

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

发布评论

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

评论(3

困倦 2025-02-13 10:29:48

如果编译器为G ++,则Clangd需要G ++的驱动程序才能找到STD库。基本上,您需要在CMD表中取消调查

If the compiler is g++, clangd needs g++'s driver to find std library. Basically you need to uncomment the queries in cmd table

手心的温暖 2025-02-13 10:29:48

很难确定这是否是问题,而又不看到 clangd logs 问题是的参数 - QUERY-DRIVER REGEX ,它与 compile_commands.json 。

我认为您所经过的逗号分隔列表不是有效的正则是。要匹配这四个可执行文件,您可能需要使用更宽松的正则义务,例如/app/vbuild/rhel7-x86_64/*/lestest/bin/bin/code> ,或否则使用替代语法( clang | gcc)等。

It's hard to be sure if this is the problem without seeing clangd logs, but one potential issue is that the argument to --query-driver is a regex that's matched against the path of the compiler executable from the commands in compile_commands.json.

I don't think the comma-separated list of paths you are passing is a valid regex. To match those four executables, you may want to use a more permissive regex like /app/vbuild/RHEL7-x86_64/*/latest/bin/*, or otherwise use alternative syntax like (clang|gcc) etc.

若无相欠,怎会相见 2025-02-13 10:29:48

After check the clangd logs. I think It's the same issue as
https://github.com/clangd/clangd/issues/1100

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