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


 Post details 

 Comments (9) 

  1. illissius says:

    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.

  2. 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.

  3. arwa says:

    I think “-recusirve” might by a typo?

  4. Of course…… fixed. Thanks for reporting.

  5. illissius says:

    Oh, I see. That’s still somewhat impressive.

  6. d bright says:

    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.

  7. d bright says:

    nevermind, i found it. you use this:

    *clang* { message(“using clang”) }

    just like you’d use *g++* or msvc*

  8. d bright says:

    newer versions of qt come with a makespec under ‘unsupported’ already. you can config like so:

    qmake -spec unsupported/linux-clang

  9. Yeps, Qt now has it, indeed!

 Leave a comment 

Your email address will not be published. Required fields are marked *

*


 © 2024 - Thomas Capricelli