Arm Mbed OS support forum

Clangd package missing error

I’ve worked with Windows OS for over 25 years and only recently switched to Linux OS… so lots to learn.

I’m using Linux Mint 19 (Ubuntu 18.04).

I installed Mbed Studio and got a message to say that it could not find clangd, which it needed for Intellisense.

I checked my package manager and indeed that package was not installed on my computer.

Now, I’ve noticed with my other software download and installs, it will tell you if it needs additional packages to operate and gives you that chance to install together. So why was this not done for the clangd package when I installed Mbed Studio?

I then went onto the llvm.org website and downloaded and installed as follows:
https://clangd.llvm.org/installation.html

Using “clangd --version” command it returns: clangd version 10.0.0-4ubuntu1~18.04.1

Yet, I am still getting that error message in Mbed Studio.

Error starting C/C++ language server. Please make sure ‘clangd’ is installed on your system. You can refer to the clangd page for instructions.

What’s missing?

PS. I’ve no idea if this is related.

This was found in the mbed-studio.log file found in the “home/####/.config/Mbed Studio” folder.

[2020-07-10T11:04:26.660] [ERROR] root/mbs-cpp-config - C/C++ configuration generation failed:
/home/####/.config/Mbed Studio/mbed-studio-tools/python/bin/python: can’t open file ‘/home/####/.config/Mbed Studio/mbed-studio-tools/clangd/generate_compile_commands.py’: [Errno 2] No such file or directory []

[2020-07-10T11:04:26.660] [ERROR] MbedStudio - Request generateConfig failed with error: C/C++ configuration generation failed:
/home/####/.config/Mbed Studio/mbed-studio-tools/python/bin/python: can’t open file ‘/home/####/.config/Mbed Studio/mbed-studio-tools/clangd/generate_compile_commands.py’: [Errno 2] No such file or directory [ ‘Error: C/C++ configuration generation failed:\n/home/####/.config/Mbed Studio/mbed-studio-tools/python/bin/python: can’t open file ‘/home/####/.config/Mbed Studio/mbed-studio-tools/clangd/generate_compile_commands.py’: [Errno 2] No such file or directory\n at ConfigurationCppServerImpl. (/tmp/.mount_mbed-sKcdxtf/resources/app/node_modules/@mbed/mbs-cpp-config/lib/backend/config-server.js:103:31)\n at step (/tmp/.mount_mbed-sKcdxtf/resources/app/node_modules/@mbed/mbs-cpp-config/lib/backend/config-server.js:47:23)\n at Object.throw (/tmp/.mount_mbed-sKcdxtf/resources/app/node_modules/@mbed/mbs-cpp-config/lib/backend/config-server.js:28:53)\n at rejected (/tmp/.mount_mbed-sKcdxtf/resources/app/node_modules/@mbed/mbs-cpp-config/lib/backend/config-server.js:20:65)’ ]

[2020-07-10T11:04:26.662] [WARN] root/mbs-cpp-config - Failed to generate compilation database: Error: Request generateConfig failed with message: C/C++ configuration generation failed:
/home/####/.config/Mbed Studio/mbed-studio-tools/python/bin/python: can’t open file ‘/home/####/.config/Mbed Studio/mbed-studio-tools/clangd/generate_compile_commands.py’: [Errno 2] No such file or directory []

I did a fresh install again to see if this improved matters, but it does not:

usrname@usrname-ComputerName:~/Downloads$ sudo ./MbedStudio-1.0.0.sh -f -y
[sudo] password for usrname:
Cleaning installation folders…
Installation folders cleaned
Downloading installation packages…
Installation packages downloaded
Extracting installation packages…
Installation packages extracted successfully
Warning: Mbed Studio needs clangd for the intellisense feature. Clangd is not available for your Linux distribution
Making binary files executable…
Binary files made executable
Cleaning old tools…
Old tools cleaned
Copying tools…
Tools copied
Copying executable file…
Executable file copied
Creating the launcher…
Launcher created
Creating uninstaller script…
Uninstaller script create in /home/usrname/.local/bin
Setting user permissions…
User permission set correctly
Copying udev rules…
udev rules copied
Cleaning up temporary files…
Temporary files cleaned
Checking github ssh key…
Adding github ssh key…
Github ssh key added
Github ssh key check completed
Checking libcurl4…
Installation was succesful but package ‘libcurl4-openssl-dev’ seems to be missing.
To install it please run:
cp /usr/lib/x86_64-linux-gnu/libcurl.so.3 /usr/lib/
apt-get install libcurl4 libcurl4-openssl-dev -y
libcurl4 checked

usrname@usrname-ComputerName:~/Downloads$ clangd --version
clangd version 10.0.0-4ubuntu1~18.04.1

Hi Gerriko,

unfortunately we cannot be sure that the clangd version released for Ubuntu 18.04 is also compatible with Linux Mint 19 without testing. As you can see from the clangd website, also clangd released for Debian is not always compatible with Ubuntu, despite the fact that Ubuntu is based on Debian.

If you want to try to add clangd to your installation on Linux Mint you can find some hekp here https://github.com/eclipse-theia/theia-cpp-extensions/tree/d7d1adb9580dfe196670c0fbb1223ab13132222b/packages/cpp#setting-clangd-executable-path-and-arguments .

Unfortunately at the moment Linux Mint is not supported so we cannot guarantee you any success.

Thanks for your feedback.

Federico - Mbed Studio Team

Thanks Federico! That link is very helpful… so it appears to be a Theia IDE issue. Will see if I can now resolve.

I followed through with the install instructions given on that page… To install Clangd on Ubuntu 18.04:

$ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
$ echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main" | sudo tee /etc/apt/sources.list.d/llvm.list
$ sudo apt-get update && sudo apt-get install -y clangd

That installs version 11.

But it does not fix the problem.

I do not quite follow as to what to do next as I do not understand how THEIA IDE application works.

What I did glean from reading through the page content on that link is that one can change settings in the IDE preferences…

But not sure what to change.

The other option is to change the CPP_CLANGD_COMMAND environment variable, but also not sure how.

I just hard coded the clangd version in preferences to “cpp.clangdExecutable”: “clangd-11”
and that cleared the error. No idea why???

Just on the aside…

I noticed that the argument syntax of this preference might be wrong “cpp.clangdArgs”: “-log=error”

I typed “clangd --help” in my terminal it tells me that the argument should be “–log=error”

PS: EDIT… for some reason the --log= error when inserted in quotes changes the double dash - - to “–”

I thought to seek clarification via theia github page earlier.

Please see the response received as it may have a bearing on what you do going forward and/or make life a whole lot easier.

I’ve encountered the same error today on Ubuntu 20.04, but unfortunately changing executable in preferences didn’t work for me.
However, I was able to make it work by hardcoding supported version of linux in installation script (MbedStudio-1.1.0.sh). After

# get linux version
 if [ -x "$(command -v lsb_release)" ]; then
   LINUX_VERSION="$(lsb_release -a 2> /dev/null | grep Description | cut -f2)"
 fi

I’ve added line LINUX_VERSION="Ubuntu 18.04" (line 622 for me), uninstalled and installed Mbed again.
This works for me, i.e. error is not showing up and code completion works, but this may not work in all cases.

Explanation:
Script now downloads clangd binaries and some python script (generate_compile_commands.py) from https://studio.mbed.com/tools/linux/clangd-ubuntu-18/clangd-8.0.2.zip and extracts them to ~/.config/Mbed Studio/mbed-studio-tools/clangd directory. Mbed seems to try using those binaries and doesn’t care about executable from preferences.

Possible improvements:

  1. Probably no need to run installation again, just download files manually and extract them in aforementioned directory.
  2. It uses binaries for 18.04 which seems to work for me (20.04) but may fail on other systems. In that case one could try installing clang and clangd for one’s system (sudo apt install ...) and replacing Mbed binaries with symlinks to system ones (ln -s /usr/bin/clangd clangd in ~/.config/Mbed Studio/mbed-studio-tools/clangd directory, same for clang-8) and leave python script as it is.

I haven’t tried those improvements and cannot confirm they work but they seem reasonable for me.

Also kudos to @gerriko for posting updates on his debugging process, there’s nothing more frustrating than seeing “it works now” as the only reply to question.

1 Like