【问题标题】:clangd cannot parse stl lib headerclangd 无法解析 stl lib 头文件
【发布时间】:2022-07-05 11:43:01
【问题描述】:

我在配置我的 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 中发现了这些错误

enter image description here

enter image description here

clangd 似乎找不到相关的 stl 标头。但我在 $CPATH 中检查了我的包含路径。它确实有 stl 标头。有谁知道如何解决这个问题? 谢谢

【问题讨论】:

    标签: c++ g++ clang clangd


    【解决方案1】:

    如果编译器是g++,clangd需要g++的驱动才能找到std库。基本上你需要取消注释 cmd 表中的查询

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-03
      • 2015-02-14
      • 2021-03-09
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      • 2018-11-18
      • 1970-01-01
      相关资源
      最近更新 更多