I read many articles and posts over the last year or so, citing how great llvm clang is. On one side it shall have a static checker that makes lint redundant, and on the other side the optimizer has an -o4 where the -o3 shall be comparable to other optimizers. On top of that, compilation speed shall be really fast. And the part that makes it interesting for folks like Apple (who uses and contributes), is that it’s licensed under a BSD style license. What more could you want?
Time to try it myself then. First I tried to compile one of my existing projects with it. Using cmake it’s very simple to use. Just create a toolchain file as if you were cross compiling, and reference it when you generate a project from it. The procedure is well described in this blog post.
I could have thought that it’s not goint to be that easy though. While it compiles without a problem, it can’t link the libraries that were compiled using gcc. That means I have to compile all the used libraries with llvm as well. Since every non trivial C++ project of mine uses boost, I’ll start with that. The clang developers themselves blogged a while ago that they succeeded in compiling boost.
As I want to use it with other projects, I might as well create debian packages for it. So, here we go. This one is going to be for ubuntu oneiric:
apt-get source libboost1.46-dev
Now comes the trial and error part. Open debian/control, and delete all packages that are not required. Since the packages will be supplementary to the official ones, no names are allowed to match, so add an llvm into the name. The -dev, -doc, -dbg packages won’t be necessary so delete them.
Next, open debian/rules and also delete references to packages that we won’t build. Add the “using clang;” and “toolset=clang” where they are needed.
Since we have all the files there, change debian/source/format to “3.0 (native)”
Then you need to make sure the libs get into the per lib installation folders in the install target (e.g. debian/libboost-serialization-llvm1.46.1). I spent some time investigated why it didn’t happen automatically, and how the mechanism works for the original libs. But then added some *.install files to the debian directory. For this to work, you’ll have to comment or delete the line in debian/rules that deletes all install files.
cd debian for LIBNAM in libboost-date-time-llvm1.46.1 libboost-filesystem-llvm1.46.1 libboost-graph-llvm1.46.1 libboost-iostreams-llvm1.46.1 libboost-program-options-llvm1.46.1 libboost-random-llvm1.46.1 libboost-regex-llvm1.46.1 libboost-serialization-llvm1.46.1 libboost-signals-llvm1.46.1 libboost-system-llvm1.46.1 libboost-thread-llvm1.46.1 do echo ${LIBNAM} | sed -e "s/-/_/g" -e "s/_llvm1.46.1/-clang42*.*/g" -e "s/libboost_//usr/lib/libboost_/g" > ${LIBNAM}.install done
Tweak, until “dpkg-buildpackage -b” is successful, and then optionally upload to the personal packet archive. My packages are available from : https://launchpad.net/~richi-paraeasy/+archive/ppa/+packages    But beware, it’s not tested yet.
For some reason this builds only on 64bit. I spent half an hour investigating, and then decided it’s not that important at the moment.
Of course this is only hacked together and not how debian packaging should work. But for trying a new compiler it’s better than just having them on the disk somewhere.
Leave a Reply