20

I've installed Qt SDK with Qt Creator on my Windows 7. LLVM & Clang installed as well. CMake was already installed. Afterwards added Clang as a compiler into: Tools -> Options... -> Build & Run -> Compilers

Then I've created Clang kit. However while creating new project (simple console application) I've no ability to choose Clang kit. There are only autodetected MSVC kits.

Maybe the problem is that "Qt version" in Clang kit is empty. But where to get qmake for it?

Nejat
  • 31,784
  • 12
  • 106
  • 138
Walking.In.The.Air
  • 682
  • 2
  • 5
  • 13

2 Answers2

12

You should also have an appropriate compiled Qt library with Clang. There is no Clang build of Qt for Windows in the download page. So you have to prepare the build environment on your machine and compile the Qt source and then assign the qmake binary path in the "Qt version" field of your kit. Or simply use another compiler the Qt binary builds for which is already present at the download page.

Nejat
  • 31,784
  • 12
  • 106
  • 138
  • 2
    As I understand Clang is the best cross platform compiler for C++ at the time, so I'd like to use it. Do you mean compile whole Qt from source or some particular parts? May be there is some documentation of the process? – Walking.In.The.Air Sep 12 '15 at 11:22
  • You have to compile at-least the modules you want to use, like core, widgets, .... May be you would go into many troubles when compiling Qt with Clang on Windows, as only VS and MinGW compilers are said to be supported and tested on Windows in the documentation : http://doc.qt.io/qt-5/windows-requirements.html#sdks-and-compilers – Nejat Sep 12 '15 at 11:43
  • @Nejat can you be a bit more specific with the following steps: *1) you have to prepare the build environment on your machine* and *2) compile the Qt source* and then *3) assign the qmake binary path in the "Qt version" field of your kit*. – cross Sep 27 '16 at 10:55
  • [Clang](https://doc.qt.io/qt-5/windows-requirements.html#clang-clang-cl) is now mentioned as having been tested for Windows. However I don't find any specific instructions on how. If I follow the [existing](https://doc.qt.io/qt-5/windows-building.html) instructions I get `'mingw32-make' is not recognized as an internal or external command`. – Zitrax Oct 12 '17 at 21:15
  • 7
    Clang on Windows produces binaries that are compatible with those built by Visual Studio, so there is no need to build Qt from source. Just use the Qt MSVC binaries. – Oktalist Nov 02 '17 at 13:45
  • Why is there a configuration option for which compiler to use, when apparently you have to recompile the whole qt environment to get it to play ball with another compiler? Seems this shouldn't even be an option you could specify if specifying anything but the one acceptable option. Is this an option or a quiz? – SteamyThePunk Jul 31 '18 at 15:56
  • @SteamyThePunk Because There's no way to guess what exact compiler was used to build the version of Qt you're linking with, and in fact you may wish to build your code with a different compiler than Qt itself was compiled with - as long as that compiler is compatible with the version of Qt that you're using. Remember that Qt Creator is a generic C/C++ IDE that merely supports Qt. The use of Qt is not necessary in your project. Rebuilding Qt with a supported compiler is not a big deal. It's pretty much a configure, make, make install - three lines in a batch file. – Kuba hasn't forgotten Monica Jun 05 '19 at 23:32
12

Nowadays, Qt ships with a mkspec called win32-clang-msvc. It uses clang-cl, which produces build output that works together with the visual studio compiler.

I installed the latest 32bit LLVM/Clang 5.0 toolchain, after installing it was automatically detected as C++-compiler "LLVM 32bit based on MSVC2015" by Qt Creator. I have the prebuilt Qt Version "Qt 5.9.2 MSVC2015 32bit" installed on my system, which uses the same architecture and MSVC version.

To use the win32-clang-msvc mkspec, I cloned the Kit "Desktop Qt 5.9.2 MSVC2015 32bit". The only things I then had to modify was to enter win32-clang-msvc as Qt mkspec and to select "LLVM 32bit based on MSVC2015" as a C++ compiler. My projects then builds with clang-cl.exe instead of cl.exe using this kit.

FourtyTwo
  • 1,616
  • 2
  • 15
  • 43
  • Does this only work for 32bit, MSVC2015 installations? I'm trying to set up clang in a MSVC2017 64bit environment and even though I'm running a shell with the MSVC2017 tools in PATH (i.e. cl.exe does work) clang doesn't find a standard library for compiling basic applications. – pwuertz Feb 20 '18 at 08:49
  • I can only confirm that it does work with MSVC2015 32 and 64 bit, when I run everything from Qt creator without changing anything in the environment. Do you see/use the LLVM toolchain in "build & run"->compilers->autodetected? When building in a shell, there might be some additional clang paths required? Might be an alternative to install MSVC2015 build tools only, however I believe it shouldn't be necessary since 2015 and 2017 are ABI-compatible. – FourtyTwo Feb 21 '18 at 08:37
  • I guess for MSVC2017 there is no autodetection support in Clang (now LLVM6), but I did manage to compile/link via command line by defining all the include and lib flags for MSVC2017. Then there is Qt: Neither QtCreator nor QBS autodetect Clang even with LLVM in PATH. Your autodetected clang is probably detected by Qt due to successful MSVC integration or some other behind the scenes logic. – pwuertz Mar 10 '18 at 09:39
  • I searched through Qt creator sources a bit: It's looking for the registry entry from llvm/clang installer, then it tries to find a msvc toolchain with matching ABI. So instead of adding to path, one needs to work with "HKEY_LOCAL_MACHINE\\SOFTWARE\\LLVM\\LLVM" (or the corresponding 64bit-entry when using 64 bit Qt-creator ) for the detection. Not sure if "WindowsMsvc2015Flavor" in the ABI detection gives a match for MSVC2017, which is theoretically ABI-compatible to MSVC2015. See [here][1]. [1]: https://code.woboq.org/qt5/qt-creator/src/plugins/projectexplorer/msvctoolchain.cpp.html#960 – FourtyTwo Mar 12 '18 at 10:59
  • Thanks for digging into the Creator code! This particular section was indeed the only thing to be adapted for msvc2017 support. I built QtCreator with another check for `Abi::WindowsMsvc2017Flavor` and LLVM popped up in the list of autodetected compilers. From there on everything worked just as you described. – pwuertz Mar 15 '18 at 19:01
  • @FourtyTwo what does "work with" the HKLM\...\LLVM key mean? You add a value to that key? – matt wilkie May 02 '19 at 22:55
  • 1
    @mattwilkie No, I just installed LLVM via official installer and then changed the path that was added by the installer under that key to the one where my own build can be found. – FourtyTwo May 03 '19 at 05:40