3

OS: Ubuntu 18.04

There are already some posts about how to install clang in Ubuntu, however many of them are out of date, and my question is specific to installing clang as part of the insallation of YouCompleteMe.

First, following the indications in this answer and in the link provided there, I ran these commands:

$ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt-add-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main"

I then ran $ vim /etc/apt/sources.list and could verify that the new lines corresponding to llvm were added, as expected. I then ran:

$ apt-get install clang-8 lldb-8 lld-8 --print-uris

to get the information about disk space needed, which in this case was:

The following NEW packages will be installed:
binfmt-support clang-8 lib32gcc1 lib32stdc++6 libc6-i386 libclang- 
common-8-dev libclang1-8 libffi-dev liblldb-8 libobjc-7-dev libobjc4 
libomp-8-dev libomp5-8 libpfm4 libpython-stdlib lld-8 lldb-8
llvm-8 llvm-8-dev llvm-8-runtime python python-lldb-8 python-minimal 
python-six python2.7 python2.7-minimal
0 upgraded, 26 newly installed, 0 to remove and 0 not upgraded.
Need to get 71,4 MB of archives.
After this operation, 412 MB of additional disk space will be used.

Now, before actually installing those packages, I read again the README file of YouCompleteMe, and noticed it says:

You can use the system libclang or clangd only if you are sure it is version 8.0.0 or higher, otherwise don't. Even if it is, we recommend using the official binaries from llvm.org if at all possible. Make sure you download the correct archive file for your OS.
We STRONGLY recommend AGAINST use of the system libclang or clangd instead of the upstream compiled binaries. Random things may break. Save yourself the hassle and use the upstream pre-built libclang or clangd.

I guess that when they say "the system libclang", they refer to the libclang I was going to install using apt-get (Is this what they actually refer to? If someone knows what they mean by "system libclang", please let me know). So, I decided to follow the LLVM link provided by them. Once there, I clicked on "Ubuntu 18.04" under the section "Pre-built binaries". Then the download of the tar.xz file started, and I then ran:

$ tar -xJf clang*.tar.xz

And this post implies I should run:

$ cd clang*
$ sudo cp -R * /usr/local/

So now I see that I have two ways of installing clang: through apt-get, and by unpacking the binary.

Is YouCompleteMe asking for an unusual way of installing clang?
What is the right way to install clang in Ubuntu 18.04?

1 Answers1

3

I'm sure that system libclang and clangd are version 8.0.0 or higher in Ubuntu 18.04.

clangd is provided by clang-tools-8 from the universe repository in Ubuntu 18.04. Clang 8 and libclang are provided by clang-8 and libclang1-8 oackages in Ubuntu 18.04. To install all of these packages open the terminal and type:

sudo apt install clang-8 libclang1-8 clang-tools-8  

I also found the official binaries from llvm.org which is a 325 MB file named clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.gz. This contains the upsteam compiled binaries that are mentioned in the README file of YouCompleteMe. Manually downloading and installing 325 MB of files seems like a lot of work to me just to install a code-completion engine for Vim which is only a 1,152 kB download and 2,852 kB installed for vim itself, so I would try installing YouCompleteMe with the Ubuntu repository packages first and check if using system packages breaks anything in YouCompleteMe.

karel
  • 122,292
  • 133
  • 301
  • 332