Skip to content
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

Closed
mickey298 opened this issue Dec 18, 2022 · 13 comments
Closed

clangd can’t find standard library headers #370

mickey298 opened this issue Dec 18, 2022 · 13 comments
Labels
clangd Clangd(lsp) related issues educational Issues that contain useful content env Issues caused by incorrect environment settings (terminal, package manager, etc.) good-first-issue Good for newcomers lsp LSP related issues usage User-specific issues

Comments

@mickey298
Copy link

OS

ubuntu 22 内核:5.15.0

neovim

$ nvim -v
NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by runner@fv-az178-366

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/share/nvim"

Run :checkhealth for more info

checkhealth

  • OK: neovim version >= 0.7.0
    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

其他

使用

if command -v curl >/dev/null 2>&1; then
    bash -c "$(curl -fsSL https://raw.githubusercontent.com/ayamir/nvimdots/HEAD/install/install.sh)"
else
    bash -c "$(wget -O- https://raw.githubusercontent.com/ayamir/nvimdots/HEAD/install/install.sh)"
fi

安装后一切都保持默认

问题

1

c/cpp的头文件找不到,同时也没有自动补全
c

2

lsplog错误
c-2
同时打开时间久了后出现轻微的卡顿。

logfile

lsp.log

1 我想问下默认安装后还需不要单独配置某种语言(默认支持哪些?)
2 如何配置?

万分感谢!

@Jint-lzxy
Copy link
Collaborator

Jint-lzxy commented Dec 18, 2022

c/cpp的头文件找不到,同时也没有自动补全

  • That's weird. First, you’ll need the standard library (and any other libraries you depend on) installed on your system. Even if you don’t actually build on this machine, clangd needs to parse the headers (which means you need to install the latest version of any modern C++ compiler on your machine). You should then set the compiler you desire here:
    -- You MUST set this arg ↓ to your c/cpp compiler location (if not included)!
    "--query-driver=/usr/bin/clang++,/usr/bin/**/clang-*,/bin/clang,/bin/clang++,/usr/bin/gcc,/usr/bin/g++",
  • The standard library headers are often found relative to the compiler. Try start clangd with "--log=verbose", (append in this table). This can tell you the cc1 command, including which paths were searched for the standard library. You can then compare this to the output of clang -### <args> to see if the search path is missing. Often the standard library headers are not found because the include folder is not in the search path of the compiler. You may use the CPATH environment variable to adjust the global search path, for example:
export CPATH="${CPATH}:/usr/local/include"
CompileFlags:
  Add: [-std=c++??]

1 我想问下默认安装后还需不要单独配置某种语言(默认支持哪些?) 2 如何配置?

  • Neovim offers IDE-like features such as real-time diagnostics and goto definitions through communicating with the language server protocol (LSP, click to read more!). The pre-configured language servers (by default) can be found here (a.k.a, gopls, sumneko_lua, clangd, jsonls, efm, html-languageserver). But you still need to install the corresponding executable! Only the configuration is provided here.
    • In neovim instances, you can use :Mason to download any language server, while the global LSPs can be installed using your favorite package manager. When you open a file, neovim will spawn the corresponding executable(s) according to the filetype deduced.
  • We use nvim-lspconfig to configure the language server. You can view the setup parameters supported by each language server here.
    • If you just want to use the default configuration, you don't need to modify anything - we will automatically complete the setup for you, just ensure that the executable has been installed 👍
    • If you need custom setup, a general template is (append here):
elseif server == "DESIRED_SERVER_NAME" then
	nvim_lsp.DESIRED_SERVER_NAME.setup({
		capabilities = capabilities,
		on_attach = custom_attach,
		settings = {--[[Your setup table--]]},
	})
  • Also, FYI the code formatting feature is provided by efm. You would also need to use :Mason or a package manager to install the corresponding executables and set it here according to the file type. You can use the default configuration of efmls-configs-nvim or setup on your own! (Click link 1 and (link 2.1, link 2.2) to see example configs)

@Jint-lzxy Jint-lzxy added good-first-issue Good for newcomers lsp LSP related issues usage User-specific issues labels Dec 18, 2022
@Jint-lzxy Jint-lzxy changed the title 无法解析c/cpp文件 clangd can’t find standard library headers Dec 18, 2022
@Jint-lzxy Jint-lzxy changed the title clangd can’t find standard library headers clangd can’t find standard library headers Dec 18, 2022
@Jint-lzxy Jint-lzxy added the env Issues caused by incorrect environment settings (terminal, package manager, etc.) label Dec 18, 2022
@Jint-lzxy Jint-lzxy pinned this issue Dec 18, 2022
@ayamir ayamir added await-response needs:response Waiting for reply from the author and removed await-response labels Dec 19, 2022
@mickey298
Copy link
Author

@Jint-lzxy Thank you for your reply!

1

both of gcc/g++ and clang/clang++ has been installed on my machine.

$which g++
/usr/bin/g++
$which clang++
/usr/bin/clang++

2

Try 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),
Get the same output using the above command.

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.

@Jint-lzxy
Copy link
Collaborator

Jint-lzxy commented Dec 19, 2022

but i did't found the file :/home/warren/.config/clangd/config.yaml

@mickey298 This is only to help you better configure clangd. It does not exist by default. You can view all available options here.


Try to run this command,not found cc1 command

You cannot use stdout of standalone clangd to view logs. You should copy "--log=verbose", to the setup table and view the logs using the lsp.log generated.

But anyway, can you first run echo '' | clang++ -v -x c++ - and paste the complete output here? I can try to confirm whether the include path is contaminated.

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

@mickey298
Copy link
Author

@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
lsp.log

@Jint-lzxy
Copy link
Collaborator

@mickey298 Can you execute the following command to determine the location of standard library header files?

  1. Update locate database (It may take some time)
sudo updatedb
  1. Then paste the output of:
locate unordered_map

here 👍

And please also include whether clang++ can compile simple cpp files like "hello world". Looks like your C++ toolchain is broken and libstdc++ is not found.

@mickey298
Copy link
Author

mickey298 commented Dec 19, 2022

@Jint-lzxy oh my god,your are right.
I'm used to using gcc/g++ compile code on this vm,And never noticed clang++ toolchain is broken.

$ 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.
  • That's weird.I don't change or modify any config about clang after ”sudo apt-get install clang"
$ 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
  • actually the correct file is located in /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/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
.....
.....
  • I found the same problem on another vm. what's wrong with clang? Does anyone have the same problems?
  • Can i just use g++ instead of clang++ by config in lsp.lua ?
  • a clearlinux system compile ok,but still have find headers problem.

@Jint-lzxy
Copy link
Collaborator

Jint-lzxy commented Dec 19, 2022

@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.

It is recommended that you uninstall and then reinstall the collection. The default search path will be configured for you during the pre-installation process. If you use clangd, it is recommended that you install the entire llvm toolchain. I'm a tad bit busy now and if you have any issues I can help you finish the installation later 👍

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 g++ 12th version. You can do that by following command and you're good to go.

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.

@mickey298
Copy link
Author

@Jint-lzxy Thank you for your time.Your really help me a lot.

  • I try to only use g++,but it didn't work ,the headers file still can't found.
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",
                        },
                        ......
  • In the above example,It seems ok if using pure c language.

ctime

timeh

@Jint-lzxy
Copy link
Collaborator

@mickey298 Did you try sudo apt install g++-12?

@mickey298
Copy link
Author

mickey298 commented Dec 19, 2022

@Jint-lzxy I am tring.. ,The network a bit of slow.

@Jint-lzxy
Copy link
Collaborator

Don't forget to change --query-driver to the installation location of clang++! Or just do a git reset.

@mickey298
Copy link
Author

@Jint-lzxy It's ok.So simple,So elegant. Very grateful for your help.

@Jint-lzxy
Copy link
Collaborator

@mickey298 Great! For those coming later, please ensure that you have a complete llvm toolchain or the latest version of GCC!

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!

@Jint-lzxy Jint-lzxy removed the needs:response Waiting for reply from the author label Dec 19, 2022
@CharlesChiuGit CharlesChiuGit added the educational Issues that contain useful content label Feb 8, 2023
@Jint-lzxy Jint-lzxy added the clangd Clangd(lsp) related issues label Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clangd Clangd(lsp) related issues educational Issues that contain useful content env Issues caused by incorrect environment settings (terminal, package manager, etc.) good-first-issue Good for newcomers lsp LSP related issues usage User-specific issues
Projects
None yet
Development

No branches or pull requests

4 participants