Ubuntu – llvm and clang installation on ubuntu

clang

So I'm trying to install Halide on my Ubuntu 12.04 (64bit). I need llvm-3.2 and clang to be installed.

Running sudo apt-get install llvm-3.2 ends up with 'package not found'.

Trying sudo apt-get install llvm or sudo apt-get install clang installs 2.9 versions. Google helped me with this

sudo add-apt-repository ppa:kxstudio-team/builds
sudo apt-get update

Now, sudo apt-get install llvm-3.2 clang-3.2 works. But when I run make in Halide folder I still get clang:Command not found.

Best Answer

Ok, so I successfully compiled Halide on Ubuntu 13.04 by installing llvm, clang, and build-essential. My only guess as to your issue is that the LLVM or clang from the PPA you installed might not have worked quite right. It seems it's actually possible to get LLVM 3.2 from Ubuntu for 12.04, via what is known as the "proposed" archive. You might try purging the LLVM you have and installing it from "proposed". I'll explain how to do that below. Since you mentioned you're new to Ubuntu (in the original question version), I'll first explain what each command you've already used does, as best I can.

So, sudo apt-get install llvm-3.2 attempts to install the package named llvm-3.2 from the current repositories enabled on your system. In your case, it couldn't be found, so the command failed. sudo apt-get install llvm installed the llvm package, which is probably a special package that just uses the most up-to-date LLVM available in your standard repositories. In your case, that was 2.9. Same idea applies to sudo apt-get install clang. sudo add-apt-repository ppa:kxstudio-team/builds adds what's called a personal package archive or PPA to your system. This lets you get more software from another repository, or software source. See https://help.launchpad.net/Packaging/PPA for more info. Finally, sudo apt-get update tells Ubuntu to get information on what packages are available from the currently available repositories. You might take a look at http://www.debian.org/doc/manuals/debian-faq/ch-pkgtools.en.html for more info on package management in Debian (most of which should apply to Ubuntu as well, since Ubuntu is based on Debian).

So, the steps to remove the packages you've got and install the versions available from precise-proposed:

  1. Use sudo apt-get purge llvm-3.2 clang-3.2 to completely remove LLVM and clang from your system.
  2. (Optional) Use sudo add-apt-repository --remove ppa:kxstudio-team/builds to remove the PPA from your system.
  3. Follow the instructions at https://wiki.ubuntu.com/Testing/EnableProposed to enable the Proposed archive (right at the top of the page), and also follow the instructions for "Selective upgrading from -proposed". The first part will enable the actual Ubuntu version of the llvm-3.2 package, and the second will keep the system from trying to upgrade everything to the Proposed versions.
  4. Use sudo apt-get update to pull in the information on what packages and versions are now available.
  5. Use sudo apt-get install llvm-3.2/precise-proposed to install LLVM 3.2, and use sudo apt-get install clang/precise-proposed to install Clang 3.0 (I think that's the version you should get).
  6. NEW STEP: Do sudo ln -s /usr/bin/llvm-config-3.2 /usr/local/bin/llvm-config to make the system treat llvm-config-3.2 (which is the llvm-config that came with llvm-3.2) as llvm-config. More completely, this creates a symbolic link (or symlink) to llvm-config-3.2 in another place where Ubuntu will look for programs (more info: ln, FHS, PATH). Thus, when you run "llvm-config", Ubuntu will find the symlink and run the program it points to (llvm-config-3.2).
  7. See if everything compiles correctly now.

Hopefully that works. I've not tested any of this, so use at your own risk, etc. I'm pretty sure, however, that it shouldn't do anything terrible.

EDIT: Note that llvm and llvm-3.2 are independent. llvm depends on llvm-2.9 (see here), while llvm-3.2 is separate (see dependencies here)

Also, I'm not sure if you know about tab completion; it can be helpful if you're looking for a command but don't quite know the name (for example, in this case, it would probably have shown that llvm-config was called llvm-config-3.2).

Related Question