1

I downloaded clang+llvm-5.0.0-linux-x86_64-ubuntu16.04.tar.xz from llvm.org

Then, I expanded the archive into a folder on my Ubuntu 16.04 LTS 64-bit machine. The contents of the expanded folder look like this:

$ ls clang+llvm-5.0.0-linux-x86_64-ubuntu16.04.tar.xz

bin docs include lib share

Question: What do I do next? Do I have to copy these into some folders myself, and if so, which ones exactly?

There is a link to this answer but I'm not able to understand it at all.

How to install CLang using precompiled binaries?

Cœur
  • 37,241
  • 25
  • 195
  • 267
adityassrana
  • 425
  • 4
  • 10

1 Answers1

1

Assuming you've downloaded version 15.0.6, for example, and your filename resembles clang+llvm-15.0.6-x86_64-linux-gnu-ubuntu-18.04.tar.xz then a couple more steps are needed.

You will need XZ decompression binaries and a compatible tar CLI which supports decompression using it (otherwise operate them on multiple successive commands by first decompressing then unwinding the tape archive).

The command to do this is: tar -x --xz --strip-components=1 -f clang+llvm-15.0.6-x86_64-linux-gnu-ubuntu-18.04.tar.xz

You should see these directories:

# Assume this is at /home/user/.local/llvm-15
.
├── bin
├── include
├── lib
├── libexec
└── share

Now any Clang++ invocations you'll make will require -I /home/user/.local/llvm-15. For example:

clang++ -c -o ./some_llvm_ext.o ./some_llvm_ext.cc -I /home/user/.local/llvm-15/include -std=c++20 -fno-exceptions -D_GNU_SOURCE

Additionally, you need to configure the LD_LIBRARY_PATH to point to your new lib directory. While you can temporarily export a new value, it's worth checking to see if it's blank otherwise you'll have this wonky colon+space thing at the end.

# For BASH / ZSH / SH
export LD_LIBRARY_PATH="$HOME/.local/llvm-15/lib:$LD_LIBRARY_PATH"

# For FISH
# Note: Some FISH configurations will require `set -gx` depending on the context.
set -x LD_LIBRARY_PATH $HOME/.local/llvm-15/lib $LD_LIBRARY_PATH

Finally, to permanently use this new gem of LLVM, explore how to use update-alternatives on Debian based distributions. Likewise read the documentation or explore article tutorials regarding /etc/ld.so.conf and any files sourced beneath /etc/ld.so.conf.d/.

Last, but most importantly, fix your PATH variable to prioritize /home/user/.local/llvm-15/bin over all others.

  • 1
    May also want to point them to [Getting Started with the LLVM System](https://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm) – David C. Rankin Mar 23 '23 at 21:47