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

Ubuntu 22.04 - C++ header file not found using Vim with YouCompleteMe #1394

Open
yapkm01 opened this issue Nov 27, 2022 · 47 comments
Open

Ubuntu 22.04 - C++ header file not found using Vim with YouCompleteMe #1394

yapkm01 opened this issue Nov 27, 2022 · 47 comments

Comments

@yapkm01
Copy link

yapkm01 commented Nov 27, 2022

Hi,
I have one PC (Ubunto 22.04) and one laptop (Ubuntu 22.04). Both have YouCompleteMe installed. The above issue only happens to the PC. I don' face this issue with the laptop. The error i am getting example 'vector file not found [pp_file_not_found]' in the VIM when editing a C++ program. I have been using YouCompleteMe on both PC and laptop without issue for more than 1 year but just found out today it's no longer working on my PC. I have attached both logs from the PC and laptop. I did a comparison between them and it looks pretty much similar aside from the clang version.

Note for both PC & laptop:

  1. Editor: Vim v8.
  2. OS: Ubuntu 22.04
  3. Both PC & laptop never had clangd installed
  4. Both PC & laptop never had clang installed

(yapkm01-/tmp):-$ clangd (PC & laptop)
Command 'clangd' not found, but can be installed with:
sudo snap install clangd # version 6.0.0+git2102885, or
sudo apt install clangd # version 1:14.0-55~exp2
See 'snap info clangd' for additional versions.
(yapkm01-/tmp):-$

  1. clang (PC & laptop)

(yapkm01-/tmp):-$ clang
Command 'clang' not found, but can be installed with:
sudo apt install clang

  1. vim 9_38.cc
#include <vector>
#include <iostream>
using namespace std;
  
 int main(){
    vector<string> v;
    for (string buffer; cin >> buffer;) {
         v.push_back(buffer);
        cout << v.capacity() << endl;
    }
      return 0;
}

PC Logs (Problematc one):

-rw------- 1 yapkm01 yapkm01 81 Nov 26 23:16 ycm_oo6s2_v4.log
-rw------- 1 yapkm01 yapkm01 34 Nov 26 23:16 ycmd_43113_stdout_a7spn9fo.log
-rw-rw-r-- 1 yapkm01 yapkm01 223808 Nov 26 23:16 preamble-524f48.pch
-rw------- 1 yapkm01 yapkm01 1417 Nov 26 23:16 clangd_stderr4vdaydqk.log
-rw------- 1 yapkm01 yapkm01 3469 Nov 26 23:18 ycmd_43113_stderr_bt1_lqds.log

(yapkm01-/tmp):-$ cat ycm_oo6s2_v4.log
2022-11-26 23:16:34,709 - ERROR - <urlopen error [Errno 111] Connection refused>

(yapkm01-/tmp):-$ cat ycmd_43113_stdout_a7spn9fo.log
serving on http://localhost:43113

(yapkm01-/tmp):-$ cat clangd_stderr4vdaydqk.log
I[23:16:34.866] clangd version 15.0.1 (https://github.com/ycm-core/llvm 708056a3d8259ce1d9fc0f15676d13b53cc23835)
I[23:16:34.866] Features: linux
I[23:16:34.866] PID: 11031
I[23:16:34.866] Working directory: /home/yapkm01/Software.Development/C++Primer/chapter9
I[23:16:34.866] argv[0]: /home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd
I[23:16:34.866] argv[1]: -header-insertion-decorators=0
I[23:16:34.866] argv[2]: -resource-dir=/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1
I[23:16:34.866] argv[3]: -limit-results=500
I[23:16:34.866] Starting LSP over stdin/stdout
I[23:16:34.867] <-- initialize(1)
I[23:16:34.868] --> reply:initialize(1) 0 ms
I[23:16:34.869] <-- initialized
I[23:16:34.869] <-- workspace/didChangeConfiguration
I[23:16:34.869] <-- textDocument/didOpen
I[23:16:34.870] Failed to find compilation database for /home/yapkm01/Software.Development/C++Primer/chapter9/9_38.cc
I[23:16:34.870] ASTWorker building file /home/yapkm01/Software.Development/C++Primer/chapter9/9_38.cc version 1 with command clangd fallback
[/home/yapkm01/Software.Development/C++Primer/chapter9]
/usr/bin/clang -resource-dir=/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1 -- /home/yapkm01/Software.Development/C++Primer/chapter9/9_38.cc
I[23:16:34.881] --> textDocument/publishDiagnostics

(yapkm01-/tmp):-$ cat ycmd_43113_stderr_bt1_lqds.log
2022-11-26 23:16:34,711 - INFO - Completion config: 50, detailing 0 candiates
2022-11-26 23:16:34,711 - INFO - Completion config: 50, detailing 0 candiates
2022-11-26 23:16:34,711 - INFO - Completion config: 50, detailing 0 candiates
2022-11-26 23:16:34,711 - INFO - Completion config: 50, detailing 0 candiates
127.0.0.1 - - [26/Nov/2022 23:16:34] "GET /ready HTTP/1.1" 200 4
2022-11-26 23:16:34,818 - INFO - Adding buffer identifiers for file: /home/yapkm01/Software.Development/C++Primer/chapter9/9_38.cc
2022-11-26 23:16:34,857 - INFO - Clangd executable found at /home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin and up to date
2022-11-26 23:16:34,858 - INFO - Using Clangd from /home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd
2022-11-26 23:16:34,858 - INFO - Computed Clangd command: ['/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd', '-header-insertion-decorators=0', '-resource-dir=/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1', '-limit-results=500']
2022-11-26 23:16:34,858 - INFO - Completion config: 50, detailing 0 candiates
2022-11-26 23:16:34,858 - INFO - Returning cached Clangd command: ['/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd', '-header-insertion-decorators=0', '-resource-dir=/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1', '-limit-results=500']
2022-11-26 23:16:34,859 - INFO - Starting Clangd: ['/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd', '-header-insertion-decorators=0', '-resource-dir=/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1', '-limit-results=500']
127.0.0.1 - - [26/Nov/2022 23:16:34] "GET /signature_help_available?subserver=cpp HTTP/1.1" 200 23
127.0.0.1 - - [26/Nov/2022 23:16:34] "POST /event_notification HTTP/1.1" 200 2
2022-11-26 23:16:34,861 - INFO - Clangd started with PID 11031
127.0.0.1 - - [26/Nov/2022 23:16:34] "POST /event_notification HTTP/1.1" 200 2
2022-11-26 23:16:34,868 - INFO - cfamily: Language server does not require resolve request
2022-11-26 23:16:34,868 - INFO - cfamily: Language server requires sync type of Incremental
2022-11-26 23:16:34,868 - INFO - cfamily: Using characters for signature triggers: (,),{,},<,>,,
127.0.0.1 - - [26/Nov/2022 23:16:34] "POST /receive_messages HTTP/1.1" 200 5063
127.0.0.1 - - [26/Nov/2022 23:16:34] "POST /semantic_completion_available HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:16:41] "POST /debug_info HTTP/1.1" 200 881
127.0.0.1 - - [26/Nov/2022 23:16:45] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:16:55] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:17:05] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:17:15] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:17:25] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:17:35] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:17:45] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:17:55] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:18:05] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:18:15] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:18:25] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:18:35] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:18:45] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:18:55] "POST /receive_messages HTTP/1.1" 200 4

LAPTOP logs (No issue one):

-rw------- 1 yapkm01 yapkm01 81 Nov 26 23:52 ycm_9vgtaolj.log
-rw------- 1 yapkm01 yapkm01 34 Nov 26 23:52 ycmd_54349_stdout_cuzmw0lr.log
-rw-rw-r-- 1 yapkm01 yapkm01 2855480 Nov 26 23:52 preamble-162cf9.pch
-rw------- 1 yapkm01 yapkm01 1416 Nov 26 23:52 clangd_stderre3ce17de.log
-rw------- 1 yapkm01 yapkm01 10838 Nov 27 00:10 ycmd_54349_stderr_phvl244j.log

(yapkm01-/tmp):-$ cat ycm_9vgtaolj.log
2022-11-26 23:52:30,682 - ERROR - <urlopen error [Errno 111] Connection refused>

(yapkm01-/tmp):-$ cat ycmd_54349_stdout_cuzmw0lr.log
serving on http://localhost:54349

(yapkm01-/tmp):-$ cat clangd_stderre3ce17de.log
I[23:52:30.849] clangd version 13.0.0 (https://github.com/ycm-core/llvm 02d1fa3185f1beeebb182b8911bfe09d3429707f)
I[23:52:30.849] Features: linux
I[23:52:30.849] PID: 6143
I[23:52:30.849] Working directory: /home/yapkm01/Software.Development/C++Primer/chapter9
I[23:52:30.849] argv[0]: /home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd
I[23:52:30.849] argv[1]: -header-insertion-decorators=0
I[23:52:30.849] argv[2]: -resource-dir=/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/13.0.0
I[23:52:30.849] argv[3]: -limit-results=500
I[23:52:30.849] Starting LSP over stdin/stdout
I[23:52:30.849] <-- initialize(1)
I[23:52:30.850] --> reply:initialize(1) 0 ms
I[23:52:30.851] <-- initialized
I[23:52:30.851] <-- workspace/didChangeConfiguration
I[23:52:30.852] <-- textDocument/didOpen
I[23:52:30.853] Failed to find compilation database for /home/yapkm01/Software.Development/C++Primer/chapter9/9_38.cc
I[23:52:30.853] ASTWorker building file /home/yapkm01/Software.Development/C++Primer/chapter9/9_38.cc version 1 with command clangd fallback
[/home/yapkm01/Software.Development/C++Primer/chapter9]
/usr/bin/clang -resource-dir=/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/13.0.0 -- /home/yapkm01/Software.Development/C++Primer/chapter9/9_38.cc
I[23:52:31.607] --> textDocument/publishDiagnostics

(yapkm01-/tmp):-$ cat ycmd_54349_stderr_phvl244j.log
2022-11-26 23:52:30,771 - INFO - Completion config: 50, detailing 0 candiates
2022-11-26 23:52:30,771 - INFO - Completion config: 50, detailing 0 candiates
2022-11-26 23:52:30,771 - INFO - Completion config: 50, detailing 0 candiates
2022-11-26 23:52:30,772 - INFO - Completion config: 50, detailing 0 candiates
127.0.0.1 - - [26/Nov/2022 23:52:30] "GET /ready HTTP/1.1" 200 4
2022-11-26 23:52:30,796 - INFO - Adding buffer identifiers for file: /home/yapkm01/Software.Development/C++Primer/chapter9/9_38.cc
2022-11-26 23:52:30,838 - INFO - Clangd executable found at /home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin and up to date
2022-11-26 23:52:30,838 - INFO - Using Clangd from /home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd
2022-11-26 23:52:30,838 - INFO - Computed Clangd command: ['/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd', '-header-insertion-decorators=0', '-resource-dir=/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/13.0.0', '-limit-results=500']
2022-11-26 23:52:30,838 - INFO - Completion config: 50, detailing 0 candiates
2022-11-26 23:52:30,839 - INFO - Returning cached Clangd command: ['/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd', '-header-insertion-decorators=0', '-resource-dir=/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/13.0.0', '-limit-results=500']
127.0.0.1 - - [26/Nov/2022 23:52:30] "GET /signature_help_available?subserver=cpp HTTP/1.1" 200 23
127.0.0.1 - - [26/Nov/2022 23:52:30] "POST /event_notification HTTP/1.1" 200 2
2022-11-26 23:52:30,840 - INFO - Starting Clangd: ['/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd', '-header-insertion-decorators=0', '-resource-dir=/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/13.0.0', '-limit-results=500']
2022-11-26 23:52:30,843 - INFO - Clangd started with PID 6143
127.0.0.1 - - [26/Nov/2022 23:52:30] "POST /event_notification HTTP/1.1" 200 2
2022-11-26 23:52:30,850 - INFO - cfamily: Language server does not require resolve request
2022-11-26 23:52:30,851 - INFO - cfamily: Language server requires sync type of Incremental
2022-11-26 23:52:30,851 - INFO - cfamily: Using characters for signature triggers: (,,
127.0.0.1 - - [26/Nov/2022 23:52:30] "POST /semantic_completion_available HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:52:31] "POST /receive_messages HTTP/1.1" 200 95
127.0.0.1 - - [26/Nov/2022 23:52:36] "POST /debug_info HTTP/1.1" 200 880
127.0.0.1 - - [26/Nov/2022 23:52:41] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:52:51] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:53:01] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:53:11] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:53:21] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:53:32] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:53:42] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:53:52] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:54:02] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:54:12] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:54:22] "POST /receive_messages HTTP/1.1" 200 4
127.0.0.1 - - [26/Nov/2022 23:54:32] "POST /receive_messages HTTP/1.1" 200 4

@HighCommander4
Copy link

HighCommander4 commented Nov 27, 2022

It looks like clangd is not able to find the standard library headers of your compiler.

What compiler are you using to build you code? Where is the compiler executable located in the fileystem?

Using --query-driver as described at https://clangd.llvm.org/troubleshooting#cant-find-standard-library-headers-map-stdioh-etc usually works as a workaround in situations like this, but note that in clangd 15 it requires your project having a compile_commands.json (this is improved in clangd 16).

@HighCommander4
Copy link

If you're able to configure YouCompleteMe to pass --log=verbose as a command-line argument to clangd, then sharing the clangd_stderr log taken with that flag might shed more light on the situation.

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

Please see my revise information. I am using g++ (/usr/bin/g++). Initially one on PC was using clangd 13 but because it didn't work i downloaded the latest YouCompleteMe which uses clangd 15.

@HighCommander4
Copy link

Can you share the output of /usr/bin/g++ -v -x c++ -E /dev/null please?

@HighCommander4
Copy link

Btw. clangd/vscode-clangd#417 is similar, I think something related to the location of the standard library include paths changed in Ubuntu 22.04.

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

Can you share the output of /usr/bin/g++ -v -x c++ -E /dev/null please?

Here it is for the one on PC (problematic one):

(yapkm01-/tmp):-$ uname -a
Linux yapkm01-m3a78-cm 5.17.2-051702-generic #202204081338 SMP PREEMPT Fri Apr 8 13:43:51 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
(yapkm01-/tmp):-$

(yapkm01-/tmp):-$ /usr/bin/g++ -v -x c++ -E /dev/null
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.3.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04) 
COLLECT_GCC_OPTIONS='-v' '-E' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/11/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE /dev/null -mtune=generic -march=x86-64 -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -dumpbase null
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/11"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/11
 /usr/include/x86_64-linux-gnu/c++/11
 /usr/include/c++/11/backward
 /usr/lib/gcc/x86_64-linux-gnu/11/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
# 0 "/dev/null"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "/dev/null"
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-E' '-shared-libgcc' '-mtune=generic' '-march=x86-64'

Here is the one on laptop (no issue one):

yapkm01-/home/yapkm01/Software.Development/C++Primer/chapter9):-$ uname -a
Linux yapkm01-F55C 5.17.2-051702-generic #202204081338 SMP PREEMPT Fri Apr 8 13:43:51 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

(yapkm01-/home/yapkm01/Software.Development/C++Primer/chapter9):-$ /usr/bin/g++ -v -x c++ -E /dev/null
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.3.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04) 
COLLECT_GCC_OPTIONS='-v' '-E' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/11/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE /dev/null -mtune=generic -march=x86-64 -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -dumpbase null
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/11"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/11
 /usr/include/x86_64-linux-gnu/c++/11
 /usr/include/c++/11/backward
 /usr/lib/gcc/x86_64-linux-gnu/11/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
# 0 "/dev/null"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "/dev/null"
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-E' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
(yapkm01-/home/yapkm01/Software.Development/C++Primer/chapter9):-$ 

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

If you're able to configure YouCompleteMe to pass --log=verbose as a command-line argument to clangd, then sharing the clangd_stderr log taken with that flag might shed more light on the situation.

I am not sure how/where/what to change here.

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

Btw. clangd/vscode-clangd#417 is similar, I think something related to the location of the standard library include paths changed in Ubuntu 22.04.

Here's my issue. Both PC & laptop is on Ubuntu 22.04 yet one on laptop is working without problem. Not sure 100% but I noticed that this issue happens on my PC after i use VIM and did a colorscheme change. I didn't do that on my laptop and so far the YouCompleteMe is working there.

@HighCommander4
Copy link

Can you share the output of /usr/bin/g++ -v -x c++ -E /dev/null please?

Here it is.

Thanks. The listed include paths seem pretty standard, it's strange that clangd cannot find them.

Next diagnostic step would be to get verbose logs.

If you're able to configure YouCompleteMe to pass --log=verbose as a command-line argument to clangd, then sharing the clangd_stderr log taken with that flag might shed more light on the situation.

I am not sure how/where/what to change here.

I don't use YCM but some googling around took me to here which shows an example of setting ycm_clangd_args. Do that with --log=verbose as the argument.

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

Can you share the output of /usr/bin/g++ -v -x c++ -E /dev/null please?

Here it is.

Thanks. The listed include paths seem pretty standard, it's strange that clangd cannot find them.

Next diagnostic step would be to get verbose logs.

If you're able to configure YouCompleteMe to pass --log=verbose as a command-line argument to clangd, then sharing the clangd_stderr log taken with that flag might shed more light on the situation.

I am not sure how/where/what to change here.

I don't use YCM but some googling around took me to here which shows an example of setting ycm_clangd_args. Do that with --log=verbose as the argument.

OK. I'll try tomorrow. Appreciate.

@georgerapeanu
Copy link

georgerapeanu commented Nov 27, 2022

Hi!
I can confirm I am having the same issue on the latest uptodate Ubuntu 22.04. I found out about this problem via YCM too.
My /usr/bin/g++ -v -x c++ -E /dev/null output is:

Using built-in specs.
COLLECT_GCC=/usr/bin/g++
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.3.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04) 
COLLECT_GCC_OPTIONS='-v' '-E' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/11/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE /dev/null -mtune=generic -march=x86-64 -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -dumpbase null
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/11"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/11
 /usr/include/x86_64-linux-gnu/c++/11
 /usr/include/c++/11/backward
 /usr/lib/gcc/x86_64-linux-gnu/11/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
# 0 "/dev/null"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "/dev/null"
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-E' '-shared-libgcc' '-mtune=generic' '-march=x86-64'

YcmDebugInfo is:

Printing YouCompleteMe debug information...
-- Resolve completions: Up front
-- Client logfile: /tmp/ycm_g9r9jbae.log
-- Server Python interpreter: /usr/bin/python3
-- Server Python version: 3.10.6
-- Server has Clang support compiled in: True
-- Clang version: clang version 15.0.1 (https://github.com/ycm-core/llvm 708056a3d8259ce1d9fc0f15676d13b53cc23835)
-- No extra configuration file found
-- C-family completer debug information:
--   Clangd running
--   Clangd process ID: 5505
--   Clangd executable: ['/home/georgerapeanu/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd', '-header-insertion-decorators=0', '-resource-dir=/home/georgerapeanu/.vim/b
undle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1', '-limit-results=500']
--   Clangd logfiles:
--     /tmp/clangd_stderrenvqo00d.log
--   Clangd Server State: Initialized
--   Clangd Project Directory: /home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8
--   Clangd Settings: {}
--   Clangd Compilation Command: False
-- Server running at: http://127.0.0.1:40395
-- Server process ID: 5486
-- Server logfiles:
--   /tmp/ycmd_40395_stdout_l418atm7.log
--   /tmp/ycmd_40395_stderr_txk76es8.log
-- Semantic highlighting supported: True
-- Virtual text supported: False
-- Popup windows supported: True

I manually extracted the following command via YcmDebugInfo:

'/home/georgerapeanu/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd', '-header-insertion-decorators=0', '-resource-dir=/home/georgerapeanu/.vim/b
undle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1', '-limit-results=500'

Executing it with --log=verbose gives

/home/georgerapeanu/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd -header-insertion-decorators=0 -resource-dir=/home/georgerapeanu/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1 -limit-results=500 --check=test.cpp --log=verbose
I[10:15:34.764] clangd version 15.0.1 (https://github.com/ycm-core/llvm 708056a3d8259ce1d9fc0f15676d13b53cc23835)
I[10:15:34.765] Features: linux
I[10:15:34.765] PID: 5555
I[10:15:34.765] Working directory: /home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8
I[10:15:34.765] argv[0]: /home/georgerapeanu/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd
I[10:15:34.765] argv[1]: -header-insertion-decorators=0
I[10:15:34.765] argv[2]: -resource-dir=/home/georgerapeanu/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1
I[10:15:34.765] argv[3]: -limit-results=500
I[10:15:34.766] argv[4]: --check=test.cpp
I[10:15:34.766] argv[5]: --log=verbose
V[10:15:34.766] User config file is /home/georgerapeanu/.config/clangd/config.yaml
I[10:15:34.766] Entering check mode (no LSP server)
I[10:15:34.766] Testing on source file /home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8/test.cpp
I[10:15:34.767] Loading compilation database...
I[10:15:34.768] Failed to find compilation database for /home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8/test.cpp
I[10:15:34.769] Generic fallback command is: /usr/lib/llvm-14/bin/clang -resource-dir=/home/georgerapeanu/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1 -- /home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8/test.cpp
I[10:15:34.770] Parsing command...
I[10:15:34.774] internal (cc1) args are: -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.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 -fcoverage-compilation-dir=/home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8 -resource-dir /home/georgerapeanu/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++ -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/x86_64-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/backward -internal-isystem /home/georgerapeanu/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1/include -internal-isystem /usr/local/include -internal-isystem /usr/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/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8 -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -no-round-trip-args -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c++ /home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8/test.cpp
I[10:15:34.774] Building preamble...
I[10:15:34.796] Indexing headers...
V[10:15:34.796] indexed preamble AST for /home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8/test.cpp version null:
  symbol slab: 0 symbols, 120 bytes
  ref slab: 0 symbols, 0 refs, 128 bytes
  relations slab: 0 relations, 24 bytes
V[10:15:34.797] Built preamble of size 223792 for file /home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8/test.cpp version null in 0.02 seconds
E[10:15:34.797] [pp_file_not_found] Line 1: 'iostream' file not found
I[10:15:34.797] Building AST...
E[10:15:34.811] [undeclared_var_use] Line 6: use of undeclared identifier 'cout'
I[10:15:34.811] Indexing AST...
V[10:15:34.812] indexed file AST for /home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8/test.cpp version null:
  symbol slab: 1 symbols, 4448 bytes
  ref slab: 1 symbols, 1 refs, 4248 bytes
  relations slab: 0 relations, 24 bytes
V[10:15:34.812] Build dynamic index for main-file symbols with estimated memory usage of 11520 bytes
I[10:15:34.812] Building inlay hints
I[10:15:34.812] Testing features at each token (may be slow in large files)
V[10:15:34.812]   0:0 #
V[10:15:34.812]     definition: 0
V[10:15:34.813]     hover: false
V[10:15:34.813]     documentHighlight: 0
V[10:15:34.813]   0:1 include
V[10:15:34.813] No heuristic index definition for include
V[10:15:34.813]     definition: 0
V[10:15:34.813]     hover: false
V[10:15:34.813]     documentHighlight: 0
V[10:15:34.814]   0:9 <
V[10:15:34.814]     definition: 0
V[10:15:34.814]     hover: false
V[10:15:34.814]     documentHighlight: 0
V[10:15:34.814]   0:10 iostream
V[10:15:34.814] No heuristic index definition for iostream
V[10:15:34.814]     definition: 0
V[10:15:34.814]     hover: false
V[10:15:34.815]     documentHighlight: 0
V[10:15:34.815]   0:18 >
V[10:15:34.815] No heuristic index definition for iostream
V[10:15:34.815]     definition: 0
V[10:15:34.815]     hover: false
V[10:15:34.815]     documentHighlight: 0
V[10:15:34.815]   2:0 using
V[10:15:34.815]     tweak: RemoveUsingNamespace
V[10:15:34.816]     definition: 0
V[10:15:34.817]     hover: true
V[10:15:34.817]     documentHighlight: 0
V[10:15:34.817]   2:6 namespace
V[10:15:34.817]     tweak: RemoveUsingNamespace
V[10:15:34.817]     definition: 0
V[10:15:34.819]     hover: true
V[10:15:34.819]     documentHighlight: 0
V[10:15:34.819]   2:16 std
V[10:15:34.819]     tweak: RemoveUsingNamespace
V[10:15:34.819]     definition: 0
V[10:15:34.821]     hover: true
V[10:15:34.821]     documentHighlight: 0
V[10:15:34.821]   2:19 ;
V[10:15:34.821]     definition: 0
V[10:15:34.822]     hover: true
V[10:15:34.822]     documentHighlight: 0
V[10:15:34.822]   4:0 int
V[10:15:34.823]     definition: 0
V[10:15:34.823]     hover: false
V[10:15:34.823]     documentHighlight: 0
V[10:15:34.823]   4:4 main
V[10:15:34.823]     definition: 1
V[10:15:34.825]     hover: true
V[10:15:34.825]     documentHighlight: 1
V[10:15:34.825]   4:8 (
V[10:15:34.825]     definition: 1
V[10:15:34.825]     hover: false
V[10:15:34.825]     documentHighlight: 1
V[10:15:34.825]   4:9 )
V[10:15:34.826]     definition: 0
V[10:15:34.826]     hover: false
V[10:15:34.826]     documentHighlight: 0
V[10:15:34.826]   4:11 {
V[10:15:34.826]     definition: 0
V[10:15:34.826]     hover: false
V[10:15:34.826]     documentHighlight: 0
V[10:15:34.826]   5:2 cout
V[10:15:34.826]     definition: 0
V[10:15:34.827]     hover: false
V[10:15:34.827]     documentHighlight: 0
V[10:15:34.827]   5:7 <<
V[10:15:34.827]     definition: 0
V[10:15:34.827]     hover: false
V[10:15:34.827]     documentHighlight: 0
V[10:15:34.827]   5:10 "ok"
V[10:15:34.827]     definition: 0
V[10:15:34.827]     hover: false
V[10:15:34.827]     documentHighlight: 0
V[10:15:34.827]   5:14 ;
V[10:15:34.828]     definition: 0
V[10:15:34.828]     hover: false
V[10:15:34.828]     documentHighlight: 0
V[10:15:34.828]   6:2 return
V[10:15:34.828]     definition: 0
V[10:15:34.828]     hover: false
V[10:15:34.828]     documentHighlight: 1
V[10:15:34.828]   6:9 0
V[10:15:34.828]     tweak: ExtractVariable
V[10:15:34.829]     definition: 0
V[10:15:34.829]     hover: false
V[10:15:34.829]     documentHighlight: 0
V[10:15:34.829]   6:10 ;
V[10:15:34.829]     definition: 0
V[10:15:34.829]     hover: false
V[10:15:34.829]     documentHighlight: 0
V[10:15:34.829]   7:0 }
V[10:15:34.829]     definition: 0
V[10:15:34.829]     hover: false
V[10:15:34.829]     documentHighlight: 0
I[10:15:34.830] All checks completed, 2 errors

The test.cpp file is a simple c++ script:

#include <iostream>

using namespace std;

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

One of the contributors of YCM said that it seems that the include paths generated by the clagnd fallback flags no longer work on 22.04

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

Can you explain more on the 'include paths generated by the clangd fallback flags no longer work on 22.04'? As explained above i have Ubuntu 22.04 installed on both PC & laptop. Yet one on laptop works without issue.

Based on your logs below, i presume you're referring to the below portion.

I[10:15:34.768] Failed to find compilation database for /home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8/test.cpp
I[10:15:34.769] Generic fallback command is: /usr/lib/llvm-14/bin/clang -resource-dir=/home/georgerapeanu/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1 -- /home/georgerapeanu/Desktop/petrozavodsk_summer_2019/day8/test.cpp
I[10:15:34.770] Parsing command...

Are you then saying the fallback failed because you don't have /usr/lib/llvm-14/bin/clang installed?

In my case it would be below.

I[23:16:34.870] ASTWorker building file /home/yapkm01/Software.Development/C++Primer/chapter9/9_38.cc version 1 with command clangd fallback
[/home/yapkm01/Software.Development/C++Primer/chapter9]
/usr/bin/clang -resource-dir=/home/yapkm01/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/15.0.1 -- /home/yapkm01/Software.Development/C++Primer/chapter9/9_38.cc

Does that mean mean /usr/bin/clang is missing which is the case on my PC (as explained above clang was never installed on both PC & laptop yet the latter works without issue)?

Can you elaborate more?

@georgerapeanu
Copy link

I can't really explain anything because I too have the problem and do not know what is happening. I just added to the issue data from my laptop in order for the smarter guys to be able to understand better what is happening.

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

Can you share the output of /usr/bin/g++ -v -x c++ -E /dev/null please?

Here it is.

Thanks. The listed include paths seem pretty standard, it's strange that clangd cannot find them.

Next diagnostic step would be to get verbose logs.

If you're able to configure YouCompleteMe to pass --log=verbose as a command-line argument to clangd, then sharing the clangd_stderr log taken with that flag might shed more light on the situation.

I am not sure how/where/what to change here.

I don't use YCM but some googling around took me to here which shows an example of setting ycm_clangd_args. Do that with --log=verbose as the argument.

Hi @HighCommander4 It seems @georgerapeanu has the logs which you need. Can you let us know what needs to be done to fix the issue? Appreciate much.

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

I can't really explain anything because I too have the problem and do not know what is happening. I just added to the issue data from my laptop in order for the smarter guys to be able to understand better what is happening.

Thanks much! Think your logs would really help them.

@HighCommander4
Copy link

I have to run now, will take a more detailed look later, but based on a quick look at the logs + another recent issue I've seen, installing g++-12 may be an effective workaround.

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

I understand .. But again here's the puzzling part. My laptop running on Ubuntu 22.04 as well. It has the same g++ version as my PC which is 11. Guess what? It's working. No issue. I am working on it right now. No error saying e.g. "vector file not found [pp_file_not_found]". I know it doesn't make sense to you but it all started on my PC on Vim after i change the color scheme. Kick me in the ass .. LOL. I'll be attaching screenshot one on my laptop showing no issue running on Ubuntu 22.04

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

Enclosed screenshot on my laptop which does not have this issue. Hope you can see it.

file:///home/yapkm01/Pictures/Screenshots/Screenshot%20from%202022-11-27%2010-18-44.png
file:///home/yapkm01/Pictures/Screenshots/Screenshot%20from%202022-11-27%2010-19-06.png
file:///home/yapkm01/Pictures/Screenshots/Screenshot%20from%202022-11-27%2010-19-27.png

@puremourning
Copy link

I was able to trivially repro this using the 'ubuntu 22.04' VM from my vagrant VMs : https://github.com/puremourning/VMs

  1. cd ubutu-22.04-LTS
  2. vagrant up (if any errors, just vagrant provision)
  3. vagrant ssh
  4. vim test.cc
  5. #include <iostream>

expect no error
actual file not found.

Workaround. Use the following compile_flags.txt:

vagrant@vagrant:~/YouCompleteMe$ cat compile_flags.txt
 -x
 c++
-std=c++17
-isystem
/usr/include/c++/11
-isystem
/usr/include/aarch64-linux-gnu/c++/11
-isystem
/usr/include/c++/11/backward
-isystem
/usr/lib/gcc/aarch64-linux-gnu/11/include
-isystem
/usr/local/include
-isystem
/usr/include/aarch64-linux-gnu
-isystem
/usr/include

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

Thanks for the tip @puremourning . Below what i did one on my PC.

a. Find where the include locations are.

(root-/):-$ find . -name vector -print
find: ‘./run/user/1000/doc’: Permission denied
find: ‘./run/user/1000/gvfs’: Permission denied
./usr/include/c++/10/vector
./usr/include/c++/10/experimental/vector
./usr/include/c++/10/debug/vector
./usr/include/c++/11/vector
./usr/include/c++/11/experimental/vector
./usr/include/c++/11/debug/vector
./usr/include/c++/9/profile/vector
./usr/include/c++/9/vector
./usr/include/c++/9/experimental/vector
./usr/include/c++/9/debug/vector
./usr/include/boost/fusion/container/vector
./usr/include/boost/mpl/vector

i choose to use ./usr/include/c++/11 location

b. Modify .ycm_extra_conf.py. Added the /usr/include/c++/11 to the last line below.

# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++11',

# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x', 'c',

'-I', '.',

'-I', './src/',

'-I', './include/',

'-I', './ClangCompleter',

'-isystem', '../llvm/include',

'-isystem', '../llvm/tools/clang/include',

'-isystem', './tests/gmock/gtest',

'-isystem', './tests/gmock/gtest/include',

'-isystem', './tests/gmock',

'-isystem', './tests/gmock/include',

'-isystem', '/usr/include',

'-isystem', '/usr/local/include',

'-isystem', '/usr/include/c++/11',

'-isystem', '/usr/include/c++/11/backward',

c. Recompiled

(yapkm01-/home/yapkm01/.vim/bundle/YouCompleteMe):-$ ./install.py --clangd-completer
Generating ycmd build configuration...OK
Compiling ycmd target: ycm_core...OK
Setting up Clangd completer...OK

d. Same error on Vim

@puremourning
Copy link

There should be no need whatsoever to recompile ycmd. I have repeatedly said that this is nothing to do with YCM or ycmd.

If you do what I said (use a compile_flags.txt in the directory of your project), it will resolve the issue. Stop fidding with YCM/ycmd - it's completely irrelevant.

@yapkm01
Copy link
Author

yapkm01 commented Nov 27, 2022

ok. I reverted back the original YCM. Below are all the compile_flags.txt. They are all under tests directory. That's all i find below. Which one i should be changing?

(yapkm01-/home/yapkm01/.vim/bundle/YouCompleteMe):-$ find . -name compile_flags.txt -print
./third_party/ycmd/ycmd/tests/clangd/testdata/compile_flags.txt
./third_party/ycmd/ycmd/tests/clangd/testdata/cuda/compile_flags.txt
./third_party/ycmd/ycmd/tests/clangd/testdata/driver_mode_cl/flag/compile_flags.txt
./third_party/ycmd/ycmd/tests/clangd/testdata/driver_mode_cl/executable/compile_flags.txt
./third_party/ycmd/ycmd/tests/clangd/testdata/test-include/compile_flags.txt
./third_party/ycmd/ycmd/tests/clangd/testdata/objc/compile_flags.txt

@puremourning
Copy link

None of them. Put the compile_flags.txt in the root of your project.

Please carefully read the clangd and YCM documentation. You do NOT need to change ANY files in the ycmd directory or the YCM directory..

I will not provide any further support on this issue as I consider it resolved (multiple times over).

@HighCommander4
Copy link

based on a quick look at the logs + another recent issue I've seen, installing g++-12 may be an effective workaround.

Two users who reported a similar issue (in #1391 and clangd/vscode-clangd#417) have reported that this workaround works.


My best guess as to how this problem arises on affected machines:

  • The affected machine has gcc-12 installed but not g++-12.
  • Since gcc-12 is installed, some paths related to gcc-12, for example /usr/lib/gcc/x86_64-linux-gnu/12, exist.
  • This fools the clang driver's heuristics for locating the standard library headers into thinking it will find gcc 12 standard library headers.
  • However, since g++-12 is not installed, the C++ standard library headers are not present.

Machines running Ubuntu 22.04 which are not affected probably either have g++-12 installed, or do not have gcc-12 installed.


With that in mind, a more complete set of workarounds:

  • Option 1 Install g++-12.
    • This is the simplest solution. It does mean that clangd will use the gcc 12 standard library headers; this may be slightly sub-optimal in cases where your project is not actually built with gcc 12 (for example, code completion may offer standard library facilities present in version 12 but not in the version you're building with).
  • Option 2 Uninstall gcc-12.
    • (But you may not be able to do this if another package you need depends on it.)
  • Option 3 Use --query-driver to instruct clangd to extract the built-in include paths of the compiler you're building with, rather than using heuristics to find them. Note that this requires that your project has a compile_commands.json, and that the argument to --query-driver match the argv[0] of the commands in the compile_commands.json.
  • Option 4 Provide the built-in include paths of your compiler to clangd manually, using a clangd config file or (for projects that don't use compile_commands.json) using compile_flags.txt. (This is the workaround @puremourning described.)

I think a proper fix would involve fixing the clang driver's heuristics for locating standard library paths, to handle this situation correctly. However, the code in question is not in clangd, it's upstream in libclangDriver, and I don't have the bandwidth to investigate it further at this time.

@puremourning
Copy link

puremourning commented Nov 28, 2022

Thanks, Nathan. I’ll double check my VM to confirm about gcc installed/g++ not installed and report back.

Edit: confirmed.

specifically:

  • gcc 12 installed
  • g++ 12 NOT installed
  • gcc 11 installed
  • g++ 11 installed

i guess a recent update required gcc 12 and caused this discrepancy. Thanks for the investigation.

@drzhivago420
Copy link

drzhivago420 commented Nov 30, 2022

Same issue here, opened some C++ code in neovim and it says <iostream> is missing
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0

@smumriak
Copy link

smumriak commented Dec 28, 2022

I've narrowed down this problem to installation of libasan8 which is the dependency of gcc-12. I'm using Pop!_os and it's desktop has hard dependency on gcc-12, but on my home server with ubuntu as a container I'm free to remove it and clang is happy again.
Installing libasan8 on itself triggers the problem even without gcc-12 installed

@adah1972
Copy link

More generally, today I find that the clang++ compilers (version 14 and 15) on Ubuntu 22.04 LTS cannot find <iostream>...

@HighCommander4
Copy link

More generally, today I find that the clang++ compilers (version 14 and 15) on Ubuntu 22.04 LTS cannot find ...

Please consider filing that upstream at https://github.com/llvm/llvm-project/issues

@adah1972
Copy link

adah1972 commented Feb 27, 2023

I have solved the problem on my computer, after some more investigations.

For some reasons gcc-12 is installed on my system (I do not think I did it), and clang is trying to use it for C++ header files (it searches directories like /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++). The problem is that only gcc-12 is installed, but not g++-12.

After installing g++-12, all problems are gone.

I have realized now it was actually one of the recommended options in this discussion. Sorry for not reading carefully. I think part of the confusion was that this issue is open. Maybe your should mark it closed to indicate there is already a solution.

@thisisdoable
Copy link

I have to run now, will take a more detailed look later, but based on a quick look at the logs + another recent issue I've seen, installing g++-12 may be an effective workaround.

I'll vouch for this solution.

@simlei
Copy link

simlei commented Jun 19, 2023

None of them. Put the compile_flags.txt in the root of your project.

Please carefully read the clangd and YCM documentation. You do NOT need to change ANY files in the ycmd directory or the YCM directory..

I will not provide any further support on this issue as I consider it resolved (multiple times over).

This man's exhaustion while not pointing fingers eventually steered me into the right direction.
My situation: I specified compile_commands.json absolute path as argument to clangd's initialization argument compilationDatabasePath. Inspection of clangd's stderr shows that the option was recognized. However, there were trivial mistakes like not finding the header in the regular project tree when using a nonstandard header directory. I was super convinced that clangd could not mess up reading that json file with all the -I {header directory} options clearly there, so I looked for the reason with YouCompleteMe.

After reading the quoted post, I resorted to verbatim copying all the compilation commands from the referenced compile_commands.json file to a compile_flags.txt file (excluding only -o <...> flags), then disabling all previous hints for clangd as to the compilation commands. Now it worked!

To me this shows one of two things:

  • either YouCompleteMe does not pass initializationOptions properly (improbable; see logs below)
  • clangd does not use that option properly (either in parsing, or applying the option at all).

clangd stderr logs, first snips:
(you will see the initializationOptions being echoed back)

I[15:35:49.350] clangd version 16.0.2 (https://github.com/llvm/llvm-project 18ddebe1a1a9bde349441631365f0472e9693520)
I[15:35:49.350] Features: linux+grpc
I[15:35:49.350] PID: 55172
I[15:35:49.350] Working directory: /home/sleischnig/sandbox/rtmaps_demo/spl-rtmaps-coec
I[15:35:49.350] argv[0]: /home/sleischnig/installations/clangd/clangd_16.0.2/bin/clangd
I[15:35:49.350] argv[1]: -header-insertion-decorators=0
I[15:35:49.350] argv[2]: -limit-results=500
I[15:35:49.350] argv[3]: -log=verbose
V[15:35:49.350] User config file is /home/sleischnig/.config/clangd/config.yaml
I[15:35:49.350] Starting LSP over stdin/stdout
V[15:35:49.350] <<< {"id":1,"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"documentationFormat":["plaintext","markdown"]},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"documentSymbol":{"hierarchicalDocumentSymbolSupport":false,"labelSupport":false,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"hover":{"contentFormat":["plaintext","markdown"]},"inlay_hint":{},"semanticTokens":{"augmentSyntaxTokens":true,"formats":["relative"],"requests":{"full":{"delta":false},"range":true},"tokenModifiers":[],"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","method","member","macro","keyword","modifier","comment","string","number","regexp","operator"]},"signatureHelp":{"signatureInformation":{"documentationFormat":["plaintext","markdown"],"parameterInformation":{"labelOffsetSupport":true}}},"synchronization":{"didSave":true}},"workspace":{"applyEdit":true,"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"workspaceEdit":{"documentChanges":true},"workspaceFolders":true}},"initializationOptions":{"compilationDatabasePath":"/home/sleischnig/sandbox/rtmaps_demo/spl-rtmaps-coec/compile_commands.json"},"processId":55104,"rootPath":"/home/sleischnig/sandbox/rtmaps_demo/spl-rtmaps-coec","rootUri":"file:///home/sleischnig/sandbox/rtmaps_demo/spl-rtmaps-coec","workspaceFolders":[{"name":"spl-rtmaps-coec","uri":"file:///home/sleischnig/sandbox/rtmaps_demo/spl-rtmaps-coec"}]}}
[...]

@HighCommander4
Copy link

@simlei can you show a complete set of clangd logs?

Also, are you having an issue resolving standard library includes like <iostream>, or your project's own includes? In the latter case, I would suggest posting a logs in a separate issue, as this issue is about resolving standard library includes on Ubunu 22.04 specifically.

@diogoizele
Copy link

diogoizele commented Jul 5, 2023

I have solved the problem on my computer, after some more investigations.

For some reasons gcc-12 is installed on my system (I do not think I did it), and clang is trying to use it for C++ header files (it searches directories like /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++). The problem is that only gcc-12 is installed, but not g++-12.

After installing g++-12, all problems are gone.

I have realized now it was actually one of the recommended options in this discussion. Sorry for not reading carefully. I think part of the confusion was that this issue is open. Maybe your should mark it closed to indicate there is already a solution.

This worked for me too.

I just installed by running on Ubuntu 22.04

sudo apt update
sudo apt install g++-12

@simlei
Copy link

simlei commented Jul 30, 2023

@simlei can you show a complete set of clangd logs?

Also, are you having an issue resolving standard library includes like <iostream>, or your project's own includes? In the latter case, I would suggest posting a logs in a separate issue, as this issue is about resolving standard library includes on Ubunu 22.04 specifically.

I'm sorry but it's simply too late now, of my own laziness to follow up timely.
However, without explicit configuration, and by putting compile_commands.json at the expected location, it works for me.

@UnionType
Copy link

UnionType commented Oct 18, 2023

I have too computers, one is Ubuntu 22.04.2 LTS, it works well, but another is Ubuntu 22.04.3 LTS, it has the same issue...

@HighCommander4
Copy link

I have too computers, one is Ubuntu 22.04.2 LTS, it works well, but another is Ubuntu 22.04.3 LTS, it has the same issue...

Have you tried the described workarounds?

My guess is the two machines differ by one of them having g++-12 installed and the other not.

@UnionType
Copy link

I have too computers, one is Ubuntu 22.04.2 LTS, it works well, but another is Ubuntu 22.04.3 LTS, it has the same issue...

Have you tried the described workarounds?

My guess is the two machines differ by one of them having g++-12 installed and the other not.

Both computers(Ubuntu 22.04.2) worked well a few months ago, neither computer has g++12 installed, when I upgrade one of them from 22.04.2 to 22.04.3, the issue arised. Now I have to install g++12 to circumvent the issue.

@HighCommander4
Copy link

HighCommander4 commented Oct 25, 2023

Both computers(Ubuntu 22.04.2) worked well a few months ago, neither computer has g++12 installed, when I upgrade one of them from 22.04.2 to 22.04.3, the issue arised.

The issue arises more specifically when gcc-12 is installed but g++-12 is not. So an explanation could be that the upgrade involved installing gcc-12.

Now I have to install g++12 to circumvent the issue.

The comment I linked to describes a number of alternative workarounds.

In my experience, the approach that produces the most accurate results is using --query-driver to make sure clangd is using the exact same library headers as your build compiler ("Option 3" from the workaround list).

@UnionType
Copy link

On the Ubuntu 22.04.3, when I switch the compiler from gcc to clang, and use libc++ instead of libstdc++, the issue persists. After I use the workarounds, everything looks like well, but when I jump to the iostream file, I found that it's the path to libstdc++ and not libc++. I tested both the clang15.07 and clang16.06,the issue is same.
Same as before,everything works fine on the Ubuntu22.04.02 without workaround, and the jump path is also right,I think this issue may be introduced by the new version of Ubuntu.

@adah1972
Copy link

@UnionType

As far as I know, using libc++ always requires the command-line option -stdlib=libc++. Did you specify that in the configuration?

@UnionType
Copy link

@UnionType

As far as I know, using libc++ always requires the command-line option -stdlib=libc++. Did you specify that in the configuration?

Of course I did, on the Ubuntu 22.04.2, it can jump to the right path of libc++.

@adah1972
Copy link

Sorry for misunderstanding.

You are right, the youcompleteme in Ubuntu 22.04 has ceased to work for C++ header files. For me, it does not work at all—it failed to find iostream, whether given -stdlib=libc++ or not.

I ended up installing the latest YouCompleteMe from scratch. Everything is back to normal.

@meinzer1899
Copy link

from #1394 (comment)
With that in mind, a more complete set of workarounds:

Workaround 1 (installing g++-12) worked for me.

It is exactly as you describe, the include paths for gcc were wrong after a Ubuntu 22.04 update installed gcc(-12?) but not g++-12.

@are-scenic
Copy link

based on a quick look at the logs + another recent issue I've seen, installing g++-12 may be an effective workaround.

Two users who reported a similar issue (in #1391 and clangd/vscode-clangd#417) have reported that this workaround works.

My best guess as to how this problem arises on affected machines:

  • The affected machine has gcc-12 installed but not g++-12.
  • Since gcc-12 is installed, some paths related to gcc-12, for example /usr/lib/gcc/x86_64-linux-gnu/12, exist.
  • This fools the clang driver's heuristics for locating the standard library headers into thinking it will find gcc 12 standard library headers.
  • However, since g++-12 is not installed, the C++ standard library headers are not present.

Machines running Ubuntu 22.04 which are not affected probably either have g++-12 installed, or do not have gcc-12 installed.

With that in mind, a more complete set of workarounds:

  • Option 1 Install g++-12.

    • This is the simplest solution. It does mean that clangd will use the gcc 12 standard library headers; this may be slightly sub-optimal in cases where your project is not actually built with gcc 12 (for example, code completion may offer standard library facilities present in version 12 but not in the version you're building with).
  • Option 2 Uninstall gcc-12.

    • (But you may not be able to do this if another package you need depends on it.)
  • Option 3 Use --query-driver to instruct clangd to extract the built-in include paths of the compiler you're building with, rather than using heuristics to find them. Note that this requires that your project has a compile_commands.json, and that the argument to --query-driver match the argv[0] of the commands in the compile_commands.json.

  • Option 4 Provide the built-in include paths of your compiler to clangd manually, using a clangd config file or (for projects that don't use compile_commands.json) using compile_flags.txt. (This is the workaround @puremourning described.)

I think a proper fix would involve fixing the clang driver's heuristics for locating standard library paths, to handle this situation correctly. However, the code in question is not in clangd, it's upstream in libclangDriver, and I don't have the bandwidth to investigate it further at this time.

@HighCommander4, I am experiencing this issue too, and in my case, only the Option 1 brought the desired effect.

@HighCommander4
Copy link

@HighCommander4, I am experiencing this issue too, and in my case, only the Option 1 brought the desired effect.

Does it suit your needs?

If you have a need to use gcc 11 headers, I'm sure Option 3 can be made to work, it's just a bit more finnicky to get right.

@ims0
Copy link

ims0 commented Jul 23, 2024

try: sudo apt remove libgcc-12-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests