# Vscode c++ cpptools and clangd not working

**URL:** https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902
**Category:** Help
**Created:** [September 22, 2022, 4:13pm UTC](https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902 "2022-09-22T16:13:57Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![dav.dap](https://discourse.nixos.org/user_avatar/discourse.nixos.org/dav.dap/32/8145_2.png) [@dav.dap](https://discourse.nixos.org/u/dav.dap)
#### Post date: [September 22, 2022, 4:13pm UTC](https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902/1 "2022-09-22T16:13:57Z")

</div>

Hi everyone,

I have `vscode-with-extensions` (unstable) on `environment.systemPackages`, with the extensions being installed manually from the extensions bar.

I got the following problem with cpptools:

```auto
[Error - 16:59:51] cpptools client: couldn't create connection to server.
Launching server using command /home/davide/.vscode/extensions/ms-vscode.cpptools-1.12.4-linux-x64/bin/cpptools failed. Error: spawn /home/davide/.vscode/extensions/ms-vscode.cpptools-1.12.4-linux-x64/bin/cpptools ENOENT

```

and the following with clangd:

```auto
[Error - 17:11:30] Clang Language Server client: couldn't create connection to server.
Launching server using command /home/davide/.config/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/15.0.0/clangd_15.0.0/bin/clangd failed. Error: spawn /home/davide/.config/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/15.0.0/clangd_15.0.0/bin/clangd ENOENT

```

In other words, no c++ tool seems to work.

EDIT the two filed actually exist, but if I try to execute them from the terminal I get no such file or directory.

Thank you 🙂

Davide

---

<div class="post-metadata">

### Author: ![TLATER](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tlater/32/4257_2.png) [@TLATER](https://discourse.nixos.org/u/TLATER)
#### Post date: [September 23, 2022, 10:15am UTC](https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902/2 "2022-09-23T10:15:51Z")

</div>

Hi! So this happens because vscode is downloading random binaries from the internet, which are built on a normal distro with the dynamic linker in the normal path, but NixOS doesn’t place the dynamic linker in the usual path.

Let me explain. If you run, e.g.,

```auto
ldd /home/davide/.vscode/extensions/ms-vscode.cpptools-1.12.4-linux-x64/bin/cpptools

```

you will get output something like this:

```auto
        linux-vdso.so.1 (0x00007ffe689dc000)
        libdl.so.2 => /nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib/libdl.so.2 (0x00007f27e9915000)
        libpthread.so.0 => /nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib/libpthread.so.0 (0x00007f27e9910000)
        libm.so.6 => /nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib/libm.so.6 (0x00007f27e8527000)
        libc.so.6 => /nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib/libc.so.6 (0x00007f27e8329000)
        /lib64/ld-linux-x86-64.so.2 => /nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib64/ld-linux-x86-64.so.2 (0x00007f27e991c000)

```

The final line there is the so-called “interpreter”, which is at the start of the file with a `#!`. It’s responsible for starting the application, and making sure all its dynamic libraries are correctly loaded.

As you see, it asks for `/lib64/...`, which doesn’t exist on NixOS - all libraries and binaries live in the nix store instead.

`ldd` is even smart enough to find a dynamic linker that would work, but when you execute the binary Linux doesn’t go looking for other files, it just uses exactly the file that the binary asks for, and then gives you the extremely unhelpful “file not found” error message you see.

There are two solutions to this problem:

1. Manually patch the binaries every time vscode downloads them
2. Use nix to install the plugins

The former can be done with [patchelf](https://github.com/NixOS/patchelf).

The latter can be done by not using vscode’s plugin browser, and instead doing something like this:

```auto
environment.systemPackages = with pkgs; [
  # <snip lots of packages>
  # ...
  (vscode-with-extensions.override {
    vscodeExtensions = with vscode-extensions; [
      ms-vscode.cpptools
      llvm-vs-code-extensions.vscode-clangd
    ];
  })
];

```

Personally, I think this is preferable 🙂

---

<div class="post-metadata">

### Author: ![dav.dap](https://discourse.nixos.org/user_avatar/discourse.nixos.org/dav.dap/32/8145_2.png) [@dav.dap](https://discourse.nixos.org/u/dav.dap)
#### Post date: [September 23, 2022, 10:58am UTC](https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902/3 "2022-09-23T10:58:56Z")

</div>

Thank you for your reply. I tried the second approach when I first approached vscode on NixOS, but I gave up as many extensions I routinely use are not present in the store. Trying to manually install extensions not containing binaries from the extensions bar gives an error:

```auto
[renderer1] [error] EACCES: permission denied, mkdir '/nix/store/syiwpv55wx6w54m1q27j63ymqkkfsgir-vscode-extensions/share/vscode/extensions/.3c51de5b-0693-41a9-8edf-5f5ba92f839a': Extract: EACCES: permission denied, mkdir '/nix/store/syiwpv55wx6w54m1q27j63ymqkkfsgir-vscode-extensions/share/vscode/extensions/.3c51de5b-0693-41a9-8edf-5f5ba92f839a'
    at J.extractAtLocation (vscode-file://vscode-app/nix/store/006i7y5prgw2iqg8ysi91wl1va019zfl-vscode-1.71.2/lib/vscode/resources/app/out/vs/code/electron-browser/sharedProcess/sharedProcessMain.js:83:164082)
    at async J.extractUserExtension (vscode-file://vscode-app/nix/store/006i7y5prgw2iqg8ysi91wl1va019zfl-vscode-1.71.2/lib/vscode/resources/app/out/vs/code/electron-browser/sharedProcess/sharedProcessMain.js:83:161465)
    at async G.extract (vscode-file://vscode-app/nix/store/006i7y5prgw2iqg8ysi91wl1va019zfl-vscode-1.71.2/lib/vscode/resources/app/out/vs/code/electron-browser/sharedProcess/sharedProcessMain.js:83:168414)
    at async G.doRun (vscode-file://vscode-app/nix/store/006i7y5prgw2iqg8ysi91wl1va019zfl-vscode-1.71.2/lib/vscode/resources/app/out/vs/code/electron-browser/sharedProcess/sharedProcessMain.js:83:169681)

```

I tried to change `environment.systemPackages` to `users.users.davide.packages` but to no avail.

Are there any hybrid solutions?

---

<div class="post-metadata">

### Author: ![TLATER](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tlater/32/4257_2.png) [@TLATER](https://discourse.nixos.org/u/TLATER)
#### Post date: [September 23, 2022, 11:00am UTC](https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902/4 "2022-09-23T11:00:07Z")

</div>

In that case you probably want to use [vscode-fhs](https://search.nixos.org/packages?channel=22.05&from=0&size=50&sort=relevance&type=packages&query=vscode) instead of vscode-with-extensions, which I just learned about!

---

<div class="post-metadata">

### Author: ![dav.dap](https://discourse.nixos.org/user_avatar/discourse.nixos.org/dav.dap/32/8145_2.png) [@dav.dap](https://discourse.nixos.org/u/dav.dap)
#### Post date: [September 23, 2022, 11:32am UTC](https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902/5 "2022-09-23T11:32:23Z")

</div>

Thank you. That does the trick, but has a problem with git:

> Git not found. Install it or configure it using the ‘git.path’ setting

The problem persists after manually editing `settings.json`. From the log:

```auto
[2022-09-23T11:26:25.313Z] [info] Validating found git in: /home/davide/.nix-profile/bin/git
[2022-09-23T11:26:25.332Z] [info] Validating found git in: git
[2022-09-23T11:26:25.338Z] [warning] Git installation not found.

```

---

<div class="post-metadata">

### Author: ![TLATER](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tlater/32/4257_2.png) [@TLATER](https://discourse.nixos.org/u/TLATER)
#### Post date: [September 23, 2022, 1:36pm UTC](https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902/6 "2022-09-23T13:36:09Z")

</div>

Hmm, it’s saying something about “validating”, any way to get a log from what that validation did? This issue might be relevant: [vscode-fhs run from nix develop cannot launch terminal or extensions with binaries · Issue #169464 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/issues/169464)

---

<div class="post-metadata">

### Author: ![dav.dap](https://discourse.nixos.org/user_avatar/discourse.nixos.org/dav.dap/32/8145_2.png) [@dav.dap](https://discourse.nixos.org/u/dav.dap)
#### Post date: [September 23, 2022, 4:13pm UTC](https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902/7 "2022-09-23T16:13:05Z")

</div>

Thank you. I solved the problem by using the stable version of `vscode-fhs` in place of the unstable one, as a user suggested.

A couple of further thoughts:  
I wonder if it would not be a better idea to use your solution 2, packaging the extension not in the store by myself? I have never packaged anything and I have no idea where to start, nor how long it would take, though.

Second - I notice some conflicts popping out when running `sudo nixos-rebuild switch`, which _apparently_ do not impact the system’s working:

```auto
warning: collision between `/nix/store/5aba3b8kk4srznz895sv9jgybs03k90m-glibc-multi-2.34-210-bin/bin/ldconfig' and `/nix/store/p5s01iqh7w0dgm7d3p5r2m4hwcj7yp6n-ldconfig/bin/ldconfig'
warning: collision between `/nix/store/akdcc3j6k15nn2l8i5mqmq6jr392ppcn-glibc-multi-2.34-210/lib/locale/locale-archive' and `/nix/store/fqmdxlbk32miazamkyavwwiwkn146i37-glibc-locales-2.34-210/lib/locale/locale-archive'
warning: collision between `/nix/store/pnqyyr621w93zqb550q5889b1ri1qah5-gcc-11.3.0-lib/lib64/libgcc_s.so.1' and `/nix/store/akdcc3j6k15nn2l8i5mqmq6jr392ppcn-glibc-multi-2.34-210/lib64/libgcc_s.so.1'
warning: collision between `/nix/store/pnqyyr621w93zqb550q5889b1ri1qah5-gcc-11.3.0-lib/lib64/libgcc_s.so' and `/nix/store/akdcc3j6k15nn2l8i5mqmq6jr392ppcn-glibc-multi-2.34-210/lib64/libgcc_s.so'
warning: collision between `/nix/store/pnqyyr621w93zqb550q5889b1ri1qah5-gcc-11.3.0-lib/lib/libgcc_s.so.1' and `/nix/store/akdcc3j6k15nn2l8i5mqmq6jr392ppcn-glibc-multi-2.34-210/lib/libgcc_s.so.1'
warning: collision between `/nix/store/pnqyyr621w93zqb550q5889b1ri1qah5-gcc-11.3.0-lib/lib/libgcc_s.so' and `/nix/store/akdcc3j6k15nn2l8i5mqmq6jr392ppcn-glibc-multi-2.34-210/lib/libgcc_s.so'
warning: collision between `/nix/store/l4b3ilygyf9vwb037dhfxf53zhhfg12q-glibc-2.34-210-bin/bin/ldconfig' and `/nix/store/p5s01iqh7w0dgm7d3p5r2m4hwcj7yp6n-ldconfig/bin/ldconfig'
warning: collision between `/nix/store/l4b3ilygyf9vwb037dhfxf53zhhfg12q-glibc-2.34-210-bin/bin/ldd' and `/nix/store/5aba3b8kk4srznz895sv9jgybs03k90m-glibc-multi-2.34-210-bin/bin/ldd'
warning: collision between `/nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib/locale/locale-archive' and `/nix/store/fqmdxlbk32miazamkyavwwiwkn146i37-glibc-locales-2.34-210/lib/locale/locale-archive'

```

plus others involving virtualbox and sushi. Perhaps this may have effects on how the system and applications read the binaries?

---

<div class="post-metadata">

### Author: ![TLATER](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tlater/32/4257_2.png) [@TLATER](https://discourse.nixos.org/u/TLATER)
#### Post date: [September 23, 2022, 4:19pm UTC](https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902/8 "2022-09-23T16:19:23Z")

</div>

> [@dav.dap](#):
>
> Second - I notice some conflicts popping out when running `sudo nixos-rebuild switch` , which _apparently_ do not impact the system’s working:

Hrm, that sounds like you are pulling things from multiple versions of nixpkgs and end up needing to have them around at the same time, or something. Can’t really judge what’s happening here without more context, but that looks quite scary.

> [@dav.dap](#):
>
> I wonder if it would not be a better idea to use your solution 2, packaging the extension not in the store by myself? I have never packaged anything and I have no idea where to start, nor how long it would take, though.

Looks like it’s actually pretty easy to do, there’s some documentation for that in the vscode-with-extensions definition: [nixpkgs/pkgs/applications/editors/vscode/with-extensions.nix at bcc68429a50c4ac051920c72c60e417202c19d79 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/blob/bcc68429a50c4ac051920c72c60e417202c19d79/pkgs/applications/editors/vscode/with-extensions.nix#L5)

---

<div class="post-metadata">

### Author: ![dav.dap](https://discourse.nixos.org/user_avatar/discourse.nixos.org/dav.dap/32/8145_2.png) [@dav.dap](https://discourse.nixos.org/u/dav.dap)
#### Post date: [September 23, 2022, 10:33pm UTC](https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902/9 "2022-09-23T22:33:26Z")

</div>

thank you for your reply, the comment in your link explains how solve the problem and now I have all the extensions working - both on the store and not!

About the conflicts - what context would be useful?

thank you 🙂  
Davide

---

<div class="post-metadata">

### Author: ![TLATER](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tlater/32/4257_2.png) [@TLATER](https://discourse.nixos.org/u/TLATER)
#### Post date: [September 23, 2022, 11:24pm UTC](https://discourse.nixos.org/t/vscode-c-cpptools-and-clangd-not-working/21902/10 "2022-09-23T23:24:44Z")

</div>

> [@dav.dap](#):
>
> About the conflicts - what context would be useful?

Your configuration, and if you’re not using a flake your channels. I’d make a new topic though; I don’t know too much about how NixOS handles collisions, so it’d be better if someone else chimes in 😉
