这个问题已被问过并回答过很多次,但似乎没有一个答案对我有用。
我一直在尝试clangd在 nvim lsp 中进行设置。我使用bear来生成compile_commands.json,但 clangd 仍然给我错误,告诉我它找不到标准库头。这是一个最小的例子:
主要.cpp:
#include <iostream>
using namespace std;
int main(){
cout << "hello clangd";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后我运行: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"
}
]
Run Code Online (Sandbox Code Playgroud)
我还尝试使用 cmake 标志进行编译来生成compile_commands.json,但我遇到了同样的问题。我可以获取该文件,但语言服务器仍然无法正常工作。
我已经能够将 clang 与vim-pio 一起使用,所以看起来它没有损坏。我缺少什么。
编辑:顺便说一句,我在 ubuntu 上