clangd: Ubuntu 22.04 - C++ header file not found using Vim with YouCompleteMe

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

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 2
  • Comments: 46

Most upvoted comments

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 https://github.com/clangd/vscode-clangd/issues/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.

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

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.

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.

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