[Qbs] Clang and linking C++ on Windows

resurrection at centrum.cz resurrection at centrum.cz
Tue May 1 22:00:13 CEST 2018


After digging around this bug report: https://bugreports.qt.io/browse/QBS-1322 <https://bugreports.qt.io/browse/QBS-1322> I was able to work around the Clang compiler not being invoked correctly on Windows when targeting x86_64 architecture. The culprit was automatically set flag "cpp.positionIndependentCode: true" that produces "-fPIC" compiler option that is apparently unsupported by Clang for that target (because it makes no sense as it is the default).
 
The second problem became the linker as neither Windows link.exe nor lldb-link.exe works because when compiling with Clang Qbs automatically assumes Linux and generates the flags for that. I am guessing that if lld was used directly it should work as it is supposed to be drop-in replacement for gcc linker however on Windows the linker is lld-link.exe that is in turn supposed to be drop in replacement for link.exe. And unfortunately it does not understand the gcc flags. I think they would not be correct anyway because passing "-soname" to the linker when Windows is the target and not appending .dll/.exe/.a suffix would require the linker to be super smart to guess what it is being asked.
 
Anyway I believe that this is either a gap in Qbs or something needs to be done when setting up the profile (no idea what). I have hacked the GenericGCC.qbs and GCC.js so the linker succeeded and produced the output but it was really just hacked in to see if it could be fixed. The Qbs currently will always be directed to these GCC specific settings because Clang automatically means GCC in Qbs. What should be done in my opinion is to add windows-clang.qbs file similar to existing windows-msvc.qbs and windows-mingw.qbs in cpp module. And of course the profile routing would need to be changed so that Clang on Windows does not automatically mean everything GCC and Linux-like. I suppose the existing windows specific qbs files could be re-used.
 
The reason why I would need it are LLVM goodies such as LTO, LLDB and LLVM code coverage tools that are pretty amazing. They are all working from the command line and even with Qt (regardless whether built with them or with MSVC) but inability to use Qbs with QtC is a problem.
 
Thanks for looking into this.
Michael

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20180501/224bb791/attachment.html>


More information about the Qbs mailing list