Important: Please read the Qt Code of Conduct -

How can I build project using Clang with QtCreator?

  • I would like to build my project with Clang and generate LLVM bitcode. I added Clang toolchain and cloned MinGW's build configuration, but setting toolchain to Clang doesn't seem to affect and project is still build with MinGW. I'm not using Qt libraries.
    What am I doing wrong?

    I'm sorry about bad English.

  • Moderators

    Most likely: Nothing.

    I never even assumed that anyone would want to use clang on windows (last time I tried clang could not build anything on windows due to incompatibilities in the headers), so if this works, then it is more or less by accident:-) I am not even sure whether clang is supposed to be compatible with mingw or msvc builds (and which versions of the latter)!

    Possible workarounds: Go to Tools->Options->Build & Run->Tool Chains and set the ABI manually to match the Qt version you want to use. Give it a try, you might need to use a msvc build Qt though for this to work.

    If you want to help to improve the support: Could you please post the output of "clang --dumpmachine" (that is two dashes, the forum messes that up!) as well as the ABI of the Qt version you managed to get to work with clang (hover the Qt version in Tools->Options->Build & Run->Qt Versions to see the ABI). Better yet: Put that information into a bug report and assign it to me. Then I won't forget:-)

  • "Clang -dumpmanchine" prints "i686-pc-win32".
    I tried Clang with "Qt 4.8.0 for Desktop - MinGW (QtSDK)" and msvc2010 version. If I change the tool chain of the "Qt 4.8.0 for Desktop - MSVC2010 (QtSDK)" to Clang, it will use mingw32-make and fail because of msvc's incompatible makefile.

    Forcing "Qt 4.8.0 for Desktop - MinGW (QtSDK)" to use Clang adding "QMAKE_CXX = clang++.exe" to projectfile seems to work with a very simple static library but linker will complain about Clang's .o files, if I try to build an application.

    So how could I first compile all sourcefiles in project
    @clang++ -emit-llvm -c file.cpp -o file.bc @

    and then link them
    @llvm-ld -link-as-library file1.bc file2.bc ... @

    Thank you for answers.

  • Moderators

    Try overriding the make command by giving your own. We only fall back to what the tool chain suggests if it is not overridden in Projects->(target)->Build->Make Step.

    I doubt that doing the linking separately will help. most likely the object files are just not compatible with each other.

  • Now it seems to work correctly and it produces llvm bitcode files.
    I used mingw32-make and I added these lines to project file:
    @TARGET_EXT = .bc
    QMAKE_EXT_OBJ = .bc
    QMAKE_CXXFLAGS += -emit-llvm
    QMAKE_CXX = clang++
    QMAKE_CC = clang
    QMAKE_LIB = llvm-ld -link-as-library -o
    QMAKE_RUN_CXX = $(CXX) $(CXXFLAGS) $(INCPATH) -c $src -o $obj
    QMAKE_RUN_CC = $(CC) $(CCFLAGS) $(INCPATH) -c $src -o $obj @

  • Hi Latexl95 ,
    How you made it work..? Please can you explain in detail,
    I am using Qt 5.0.2 and windows 7 , and i just downloaded llvm 3.3 and clang 3.3. How can i compile my code with clang and how to generate the bitcode using llvm.


Log in to reply