Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 453
Walking.In.The.Air Avatar asked Sep 11 '15 22:09

Walking.In.The.Air


People also ask

Can I use Clang instead of GCC?

You can use Clang instead of GCC as a compiler for any package by overriding stdenv , which contains the compilation toolchain, with: stdenv = pkgs.


2 Answers

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.

like image 116
Nejat Avatar answered Oct 02 '22 18:10

Nejat


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.

like image 25
FourtyTwo Avatar answered Oct 02 '22 18:10

FourtyTwo