(this question similar to this one but is not the same)
I'm using QtCreator on Windows platform, usually with vc toolchain. sometimes with MinGW-W64, so for now, I'd like to try clang for some reasons. unlike the post above - I don't use Qt library , just qtcreator as IDE, so I suppose I don't need to re-build it and QtCreator for a using clang kit, is it correct?
there are a few questions about that:
and finally - how to configure all this in qtcreator?
The following steps apply only to MSYS2 64-bit installation of QT Creator 4.5.1 (install instructions here ), where you also have MinGW-w64 and mingw32-make installed on MSYS2; and you are building a non-QT C or C++ application.
These instructions use QMake, because QBS doesn't support MSYS2 clang. Well, QMake doesn't support it either, but I did figure out how to add support to QMake and I didn't figure out QBS.
There is QMake support for MSVC-clang but it outputs MSVC makefiles, so you can't build it with MSYS2 make. So that does not apply to us.
pacman
. I used pacman -Ss mingw-w64-x86_64-clang
, your flavour may vary. /msys64/mingw64/share/qt5/mkspecs/
cp -a win32-g++ win32-clang-msys
win32-clang-msys/qmake.conf
and change gcc
to clang
, and g++
to clang++
(2 places each) -fno-keep-inline-dllexport -mthreads
which are not supported by clang. /mingw64/bin/clang.exe
under your MSYS2 install). clang++.exe
in the same place) Clang
and set those two compilers as its compilers. win32-clang-msys
Now you can attempt to build your project with the Clang
kit and QMake.
I initially tried with QBS and the build failed due to this bug . But the build commands do succeed if I copy-paste them and cut out the bogus -target
switch. So for QBS users I guess you have to switch to QMake in the meantime until they fix that bug.
Troubleshooting: I sometimes got an error Project ERROR: failed to parse default search paths from compiler output
. This is a problem with QMake's lack of support for clang. The error tended to not occur if I built in a subdirectory of the .pro
file, but did occur if I built in a sibling directory.
As a workaround: go back into win32-clang-msys/qmake.conf
. Change the first clang
back to g++
. Then "Run Qmake" (from QT creator or commandline), then change it back. The first time you run QMake it writes the file .qmake.stash
and then does not need to generate it again. The contents of this file were bogus for me but building seemed to work anyway.
Undefined references: I found that linking with -static
produced a bunch of undefined references to __imp__cxa_
names. Not sure what the problem is here but maybe related to the bug with generating .qmake.stash
. I guess the Qt developers would need to officially add non-MSVC Clang support to QMake.
Multiple definitions: The CLang linker gave multiple definitions for inline DLLexport functions. I found no workaround yet for this; g++ has -fno-keep-inline-dllexport
to avoid this problem but CLang 5 does not support that flag.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.