-
Notifications
You must be signed in to change notification settings - Fork 462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clangd can’t find standard library headers #370
Comments
export CPATH="${CPATH}:/usr/local/include"
CompileFlags:
Add: [-std=c++??]
elseif server == "DESIRED_SERVER_NAME" then
nvim_lsp.DESIRED_SERVER_NAME.setup({
capabilities = capabilities,
on_attach = custom_attach,
settings = {--[[Your setup table--]]},
})
|
clangd
can’t find standard library headers
@Jint-lzxy Thank you for your reply! 1both of gcc/g++ and clang/clang++ has been installed on my machine. $which g++
/usr/bin/g++ $which clang++
/usr/bin/clang++ 2Try to run this command,not found cc1 command $ clangd --background-index --pch-storage=memory --query-driver=/usr/bin/clang++,/usr/bin/**/clang-*,/bin/clang,/bin/clang++,/usr/bin/gcc,/usr/bin/g++ --clang-tidy --all-scopes-completion --cross-file-rename --completion-style=detailed --header-insertion-decorators --header-insertion=iwyu --log=verbose
The flag `-cross-file-rename` is obsolete and ignored.
clangd is a language server that provides IDE-like features to editors.
It should be used via an editor plugin rather than invoked directly. For more information, see:
https://clangd.llvm.org/
https://microsoft.github.io/language-server-protocol/
clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment variable.
I[12:53:17.264] Ubuntu clangd version 14.0.0-1ubuntu1
I[12:53:17.264] Features: linux+grpc
I[12:53:17.264] PID: 2405
I[12:53:17.264] Working directory: /home/warren
I[12:53:17.264] argv[0]: clangd
I[12:53:17.264] argv[1]: --background-index
I[12:53:17.264] argv[2]: --pch-storage=memory
I[12:53:17.264] argv[3]: --query-driver=/usr/bin/clang++,/usr/bin/**/clang-*,/bin/clang,/bin/clang++,/usr/bin/gcc,/usr/bin/g++
I[12:53:17.264] argv[4]: --clang-tidy
I[12:53:17.264] argv[5]: --all-scopes-completion
I[12:53:17.264] argv[6]: --cross-file-rename
I[12:53:17.264] argv[7]: --completion-style=detailed
I[12:53:17.264] argv[8]: --header-insertion-decorators
I[12:53:17.264] argv[9]: --header-insertion=iwyu
I[12:53:17.264] argv[10]: --log=verbose
V[12:53:17.264] User config file is /home/warren/.config/clangd/config.yaml
I[12:53:17.264] Starting LSP over stdin/stdout but i did't found the file :/home/warren/.config/clangd/config.yaml . So i copy it from #193 (comment), The error still exists,Did i missing any thing? PS:I will try install and config neovim on a new vm ,See if they have the same problem.post results later. |
@mickey298 This is only to help you better configure
You cannot use stdout of standalone But anyway, can you first run Example Output
Homebrew clang version 15.0.6
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
"/usr/local/Cellar/llvm/15.0.6/bin/clang-15" -cc1 -triple x86_64-apple-macosx12.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -target-sdk-version=13.1 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=lldb -target-linker-version 820.1 -v -fcoverage-compilation-dir=<user-directory> -resource-dir /usr/local/Cellar/llvm/15.0.6/lib/clang/15.0.6 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I. -I/usr/local/include -stdlib=libc++ -internal-isystem /usr/local/opt/llvm/bin/../include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /usr/local/Cellar/llvm/15.0.6/lib/clang/15.0.6/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -fdeprecated-macro -fdebug-compilation-dir=<user-directory> -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/jy/91xg_8j9169dydct2k4r7yw80000gn/T/--b5727a.o -x c++ -
clang -cc1 version 15.0.6 based upon LLVM 15.0.6 default target x86_64-apple-darwin21.6.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
.
/usr/local/include
/usr/local/opt/llvm/bin/../include/c++/v1
/usr/local/Cellar/llvm/15.0.6/lib/clang/15.0.6/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -demangle -lto_library /usr/local/Cellar/llvm/15.0.6/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -platform_version macos 12.0.0 13.1 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -o a.out -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib /var/folders/jy/91xg_8j9169dydct2k4r7yw80000gn/T/--b5727a.o -lc++ -lSystem /usr/local/Cellar/llvm/15.0.6/lib/clang/15.0.6/lib/darwin/libclang_rt.osx.a |
@Jint-lzxy my fault. misunderstanding the "--log=verbose" means. $ echo '' | clang++ -v -x c++ - -v
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/usr/lib/llvm-14/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -v -fcoverage-compilation-dir=/home/warren -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/x86_64-linux-gnu -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir=/home/warren -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/--f9bfb5.o -x c++ -
clang -cc1 version 14.0.0 based upon LLVM 14.0.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/backward"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++
/usr/lib/llvm-14/lib/clang/14.0.0/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
"/usr/bin/ld" -pie -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /lib/x86_64-linux-gnu/Scrt1.o /lib/x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/12/crtbeginS.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/12 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/usr/lib/llvm-14/bin/../lib -L/lib -L/usr/lib /tmp/--f9bfb5.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib/gcc/x86_64-linux-gnu/12/crtendS.o /lib/x86_64-linux-gnu/crtn.o
/usr/bin/ld: 找不到 -lstdc++: 没有那个文件或目录
clang: error: linker command failed with exit code 1 (use -v to see invocation) Here is new logfile with --log=verbose |
@mickey298 Can you execute the following command to determine the location of standard library header files?
sudo updatedb
locate unordered_map here 👍 And please also include whether |
@Jint-lzxy oh my god,your are right. $ clang++ -c test_compile.cpp -o test -v
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
(in-process)
"/usr/lib/llvm-14/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test_compile.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/warren/c++projects -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/x86_64-linux-gnu -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir=/home/warren/c++projects -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o test -x c++ test_compile.cpp
clang -cc1 version 14.0.0 based upon LLVM 14.0.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/backward"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++
/usr/lib/llvm-14/lib/clang/14.0.0/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
test_compile.cpp:1:9: fatal error: 'iostream' file not found
#include<iostream>
^~~~~~~~~~
1 error generated.
$ ls -lh /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++
总用量 12K
drwxr-xr-x 12 root root 12K 10月 25 14:34 11
$ ls -lh /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/11
总用量 1.9M
-rw-r--r-- 1 root root 3.0K 5月 1 2022 algorithm
-rw-r--r-- 1 root root 19K 5月 1 2022 any
-rw-r--r-- 1 root root 14K 5月 1 2022 array
-rw-r--r-- 1 root root 47K 5月 1 2022 atomic
drwxr-xr-x 2 root root 4.0K 10月 25 14:34 backward
-rw-r--r-- 1 root root 7.6K 5月 1 2022 barrier
-rw-r--r-- 1 root root 12K 5月 1 2022 bit
drwxr-xr-x 2 root root 20K 10月 25 14:34 bits
-rw-r--r-- 1 root root 45K 5月 1 2022 bitset
-rw-r--r-- 1 root root 1.7K 5月 1 2022 cassert
-rw-r--r-- 1 root root 1.4K 5月 1 2022 ccomplex
-rw-r--r-- 1 root root 2.4K 5月 1 2022 cctype
-rw-r--r-- 1 root root 1.8K 5月 1 2022 cerrno
-rw-r--r-- 1 root root 2.1K 5月 1 2022 cfenv
-rw-r--r-- 1 root root 1.9K 5月 1 2022 cfloat
-rw-r--r-- 1 root root 20K 5月 1 2022 charconv
-rw-r--r-- 1 root root 95K 5月 1 2022 chrono
-rw-r--r-- 1 root root 2.2K 5月 1 2022 cinttypes
-rw-r--r-- 1 root root 1.5K 5月 1 2022 ciso646
-rw-r--r-- 1 root root 1.9K 5月 1 2022 climits
-rw-r--r-- 1 root root 1.9K 5月 1 2022 clocale
.....
.....
|
@mickey298 No, because clang cannot actually locate the header files. Although LLVM and GCC are compatible, you may not have set the correct environment for clang (because g++ takes precedence, now clang can't have its own header libraries for c++, so it is pointing towards gcc's library folder to access header files). Also the file search path is very confusing. It would be a better idea to stick to a specific compiler, otherwise it will lead to confusion. It is not enough to just install clang. You also need the whole llvm tool chain.
Ahh I see the problem. From Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12 It can be seen that clang has selected gcc's 12th version which you didn't had installed and thus the error because it can't find one! The solution is to install sudo apt install g++-12 The real problem is that your GCC version is too old. Please make sure you have the latest version of the compiler. |
@Jint-lzxy Thank you for your time.Your really help me a lot.
nvim_lsp.clangd.setup({
capabilities = copy_capabilities,
single_file_support = true,
on_attach = custom_attach,
cmd = {
"clangd",
"--background-index",
"--pch-storage=memory",
-- You MUST set this arg ↓ to your clangd executable location (if not included)!
--"--query-driver=/usr/bin/clang++,/usr/bin/**/clang-*,/bin/clang,/bin/clang++,/usr/bin/gcc,/usr/bin/g++",
"--query-driver=/usr/bin/gcc,/usr/bin/g++",
"--clang-tidy",
"--all-scopes-completion",
"--cross-file-rename",
"--completion-style=detailed",
"--header-insertion-decorators",
"--header-insertion=iwyu",
},
......
|
@mickey298 Did you try |
@Jint-lzxy I am tring.. ,The network a bit of slow. |
Don't forget to change --query-driver to the installation location of clang++! Or just do a git reset. |
@Jint-lzxy It's ok.So simple,So elegant. Very grateful for your help. |
@mickey298 Great! For those coming later, please ensure that you have a complete For detailed explanation, please refer to the discussion above 👍 Gonna close it now. If you encounter other similar problems, feel free to reopen this issue at any time! |
OS
ubuntu 22 内核:5.15.0
neovim
checkhealth
23 - OK: Go:
go version go1.18.1 linux/amd64
22 - OK: cargo:
cargo 1.65.0 (4bc8f24d3 2022-10-20)
21 - WARNING: luarocks: not available
20 - WARNING: Ruby: not available
19 - WARNING: RubyGem: not available
18 - WARNING: Composer: not available
17 - WARNING: PHP: not available
16 - OK: npm:
6.14.8
15 - OK: node:
v14.9.0
14 - OK: python3:
Python 3.10.6
13 - OK: pip3:
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
12 - OK: javac:
javac 18.0.2-ea
11 - OK: java:
openjdk version "18.0.2-ea" 2022-07-19
10 - WARNING: julia: not available
9 - OK: wget:
GNU Wget 1.21.2 在 linux-gnu 上编译。
8 - OK: curl:
curl 7.81.0 (x86_64-pc-linux-gnu) libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 ↳ brotli/1.0.9 zstd/1.4.8 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.2) libssh/0.9.6/openssl/zlib ↳ nghttp2/1.43.0 librtmp/2.3 OpenLDAP/2.5.13
7 - OK: gzip:
gzip 1.10
6 - OK: tar:
tar (GNU tar) 1.34
5 - WARNING: pwsh: not available
4 - OK: bash:
GNU bash,版本 5.1.16(1)-release (x86_64-pc-linux-gnu)
3 - OK: sh:
Ok
2 - OK: python3_host_prog:
Python 3.10.6
1 - OK: python3_host_prog pip:
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
50 - OK: GitHub API rate limit. Used: 0. Remaining: 60. Limit: 60. Reset: 2022年12月18日 星期日
packersync
所有都是already up to date
其他
使用
安装后一切都保持默认
问题
1
c/cpp的头文件找不到,同时也没有自动补全
2
lsplog错误
同时打开时间久了后出现轻微的卡顿。
logfile
lsp.log
1 我想问下默认安装后还需不要单独配置某种语言(默认支持哪些?)
2 如何配置?
万分感谢!
The text was updated successfully, but these errors were encountered: