简体   繁体   English

clangd 不识别标准标头

[英]clangd doesn't recognize standard headers

This question has been asked and answered a bunch of times, but none of the answers seem to work for me.这个问题已经被问过和回答过很多次了,但似乎没有一个答案对我有用。

I've been trying to get clangd set up in nvim lsp.我一直在尝试在clangd lsp 中设置 clangd。 I used bear to generate compile_commands.json , but clangd still gives me errors telling me it can't find standard library headers.我用bear生成了compile_commands.json ,但是 clangd 仍然给我错误,告诉我它找不到标准库头文件。 Here's a minimal example:这是一个最小的例子:

main.cpp:主.cpp:

#include <iostream>
using namespace std;

int main(){
  cout << "hello clangd";
  return 0;
}

I then run: bear -- g++ main.cpp , which compiles and creates a compile_commands.json with this content:然后我运行: bear -- g++ main.cpp ,它编译并创建一个包含以下内容的compile_commands.json

[
  {
    "arguments": [
      "/usr/bin/g++",
      "-c",
      "main.cpp"
    ],
    "directory": "/home/xxx/tmp/hello_clangd",
    "file": "/home/xxx/tmp/hello_clangd/main.cpp"
  }
]

I also tried compiling using a cmake flag to generate compile_commands.json but I'm getting the same issue.我还尝试使用 cmake 标志进行编译以生成compile_commands.json但我遇到了同样的问题。 I can get the file but the language server still won't work properly.我可以获取文件,但语言服务器仍然无法正常工作。

I have been able to use clang with vim-pio so it seems it's not broken.我已经能够将 clang 与vim-pio一起使用,所以它似乎没有损坏。 what am I missing.我错过了什么。

EDIT: I'm on ubuntu btw编辑:我在 ubuntu 顺便说一句

I had a similar issue on Pop._OS 22.04 LTS using lunarvim 1,2 and Clang++/Clangd seems to look for the newest available libraries, so instead of parsing the "11" directory (which contained "libstdc++").我在使用 lunarvim 1,2 的 Pop._OS 22.04 LTS 上遇到了类似的问题,而 Clang++/Clangd 似乎在寻找最新的可用库,而不是解析“11”目录(其中包含“libstdc++”)。 it parses the "12" directory (which did not contain "libstdc++") for the libraries.它为库解析“12”目录(不包含“libstdc++”)。

ls /usr/lib/gcc/x86_64-linux-gnu/
11  12

I searched for the version I needed.我搜索了我需要的版本。

apt search libstdc++

Problem was solved after installing the "libstdc++" for gcc version 12 from the apt repository.从 apt 存储库安装 gcc 版本 12 的“libstdc++”后问题得到解决。

apt install libstdc++-12-dev

I used this post to solve the issue我用这篇文章来解决这个问题

I have found a solution myself using clang++ using the instructions here .我已经按照此处的说明使用 clang++ 自己找到了解决方案。 The command that works for me is:对我有用的命令是:

bear -- clang++ -I/usr/include/c++/11 -I/usr/include/x86_64-linux-gnu/c++/11 -L /usr/lib/gcc/x86_64-linux-gnu/11 main.cpp

It's still a bit confusing to me so I'm open to better solutions and explanations.我仍然有点困惑,所以我愿意接受更好的解决方案和解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM