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. I used bear to generate compile_commands.json
, but clangd still gives me errors telling me it can’t find standard library headers.
Here’s a minimal example:
main.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:
[
{
"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. 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. what am I missing.
EDIT: I’m on ubuntu btw
2
Answers
I have found a solution myself using clang++ using the instructions here. The command that works for me is:
It's still a bit confusing to me so I'm open to better solutions and explanations.
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++"), it parses the "12" directory (which did not contain "libstdc++") for the libraries.
I searched for the version I needed.
Problem was solved after installing the "libstdc++" for gcc version 12 from the apt repository.
I used this post to solve the issue