Tuesday, March 19, 2013

Nerd Food: Installing Clang Unstable on Debian Testing

Nerd Food: Installing Clang Unstable on Debian Testing

We find clang an extremely useful development compiler. Not only does it pick up errors that GCC tends to ignore, but it also provides us with a completion mode in emacs that works surprisingly well.

So it was with great sadness that, for some inexplicable reason, our clang 3.1 build started failing after a dist-upgrade. After trying some obvious fixes such as doing a clean build and so on - to no avail - I decided to investigate clang 3.2, which has already hit experimental. Hey, worth a go right?! I've never been brave enough to start pinning packages from experimental into testing - always afraid to upgrade something by mistake. Clang tends to be really easy to install by hand so its not a problem to handle dependencies manually. This was almost the case with 3.2.

First start by removing all the old LLVM and clang packages you got lying around. They are actually side-by-side installable for the most part, but I strongly believe its a bad idea to have these versions lying around unless you have very good reason to do so. Last thing you need is to use the incorrect version of the compiler and start getting some weird errors.

Downloading the required packages is pretty straightforward:

mkdir clang-3.2
cd clang-3.2
wget http://ftp.us.debian.org/debian/pool/main/c/clang/libclang-dev_3.2-1~exp8_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/c/clang/libclang1_3.2-1~exp8_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/l/llvm-3.2/llvm-3.2-runtime_3.2-3_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/l/llvm-3.2/llvm-3.2_3.2-3_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/l/llvm-3.2/llvm-3.2-dev_3.2-3_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/l/llvm-3.2/libllvm3.2_3.2-3_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/c/clang/libclang-common-dev_3.2-1~exp8_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/c/clang/compiler-rt_3.2-1~exp8_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/c/clang/clang-3.2_3.2-1~exp8_amd64.deb

To install them su to root and dpkg them in the correct order:

dpkg -i libllvm3.2_3.2-3_amd64.deb
dpkg -i llvm-3.2-runtime_3.2-3_amd64.deb
dpkg -i llvm-3.2_3.2-3_amd64.deb
dpkg -i llvm-3.2-dev_3.2-3_amd64.deb
dpkg -i libclang1_3.2-1~exp8_amd64.deb
dpkg -i libclang-common-dev_3.2-1~exp8_amd64.deb
dpkg -i libclang-dev_3.2-1~exp8_amd64.deb
dpkg -i compiler-rt_3.2-1~exp8_amd64.deb
dpkg --force-depends -i clang-3.2_3.2-1~exp8_amd64.deb

You won't fail to notice the extremely worrying --force-depends at the very end. This is because to reasons unknown to me, clang now depends on libgcc-4.7-dev and libobjc-4.7-dev. These packages are not yet available in testing and last thing you need is to pull GCC straight of unstable. Assuming that any dependency between clang and GCC is probably either a mistake or something optional, I decided to force an install anyway and see how the compiler behaved. As it turns out the compiler worked just fine so I'm not loosing any sleep over the missing dependency just yet.

Unfortunately the hacks don't end there. We also found that libprofile_rt never quite gets found, so an additional hack is required (as root):

cd /usr/lib
rm libprofile_rt.a libprofile_rt.so
ln -s /usr/lib/llvm-3.2/lib/libprofile_rt.a
ln -s /usr/lib/llvm-3.2/lib/libprofile_rt.so

Interestingly, the warnings on clang 3.2 are even better than on 3.1 and so it picked up a number of unused member variables in your code, which we duly fixed. Hopefully it will all go green on tomorrow's clean builds.

Date: 2013-03-19 21:59:47 GMT

Org version 7.8.02 with Emacs version 23

Validate XHTML 1.0

No comments: