Playing with clang and Qt
You might know that there’s a new kid in the C++ compilers list ; clang. Llvm has been around for quite some time, but until recently the only way to make use of it was through the somehow cumbersome llvm-gcc which binds the gcc C/C++ frontend to the llvm backend. People (mostly Apple) have been working since 2005 on a frontend dedicated to llvm, clang. It is already used ‘in production’ by Apple for the C and objective-c languages.
The C++ part is still very alpha, but i still wanted to play with it. Among other things I wanted to try compiling some Qt projects using qmake. So i hacked this quick&dirty linux-clang mkspec. To use it, uncompress the tgz in your $(QTDIR)/mkspecs/ , edit the clang.conf file to suite your own paths, and do something like:
qmake -recursive -spec linux-clang
make
I’m using it with Qt-4.6, and it works for me (c). As a last advice, I highly recommend the svn trunk instead of the last release for clang. The website has clear information about how to do this.
* Download linux-clang.qt-4.6.mkspecs.tgz
Wait, it compiles a functional Qt already? That’s pretty amazing. Last I had heard it was building LLVM and linking, but the resulting binary was a long way off from working properly.
No, I did not test compiling Qt itself. I’m telling qmake to use clang for compiling instead of (say) gcc or visual studio. I manage to compile my project with this setup. At this stage, the main purpose is to test clang.
I think “-recusirve” might by a typo?
Of course…… fixed. Thanks for reporting.
Oh, I see. That’s still somewhat impressive.
Thomas: This is great, thank you. My question is how do you detect clang inside a qmake .pro script? clang { } doesnt seem to work. Thanks again.
nevermind, i found it. you use this:
*clang* { message(“using clang”) }
just like you’d use *g++* or msvc*
newer versions of qt come with a makespec under ‘unsupported’ already. you can config like so:
qmake -spec unsupported/linux-clang
Yeps, Qt now has it, indeed!