How to use Clang as a compiler with Qt Creator on Windows?
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?
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.
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.