Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors in QT headers using clang

Tags:

c++

clang

qt4

Questions:


My question is thus: How do I build my QT project without turning off warnings altogether (or having to sort through a million purposeless ones to find my own)? Can I suppress warnings for just the QT headers?

Details:


Issue


A number of months ago, I started a QT project in QT-Creator. At the time I was using gcc 4.6. After a bit other priorities asserted themselves and I found myself without time to work on the project until now. In the interim I switched to using clang. When I configured my QT project to use clang -- which project compiled without warnings in g++ -- it generated some 263 warnings all within the QT headers themselves. Mostly sign-conversion and unreachable-code.


Attempts


To try and get around this I added -isystem /path/to/QT/include/dir based on this entry in the Clang User Manual, but it did not seem to affect anything. Though I am not certain, I think it is because my code #include's the QT headers by name, not by directory. While the solution to that might be to manually list every single QT header used (have not tried), it would mean I would have to update it every time I upgraded QT or used a new header. Surely there is a better solution.

As requested here is the actual compile command being executed:

clang++ -c -pipe -Qunused-arguments -Weverything -cxx-isystem /path/to/qt/4.8.3/include/ -g -D_REENTRANT -DQT_NO_KEYWORDS -DQT_SHARED -I/path/to/qt/x86_64/4.8.3/mkspecs/unsupported/linux-clang -I. -I.moc -I.ui -I/path/to/qt/4.8.3/include/ -o .obj/main.o main.cpp

Specs


I am using:

  • Linux 3.2.0-40-generic #64-Ubuntu SMP x86_64 GNU/Linux
    • Though others on my team use Windows
  • QT creator 2.6.2
  • QT 4.8.3
  • clang version 3.2 (trunk 165250) (llvm/trunk 165249)
    • Target: x86_64-unknown-linux-gnu
like image 942
Tsubashi Avatar asked Apr 25 '13 18:04

Tsubashi


2 Answers

I will answer my own question because, as it turns out, it is a specific environmental quirk in this case.

I have two copies of the QT libraries on my dev machine, one system-wide and one project specific (included in the VCS). The project libraries do not have qmake included, so I used my system qmake, which appended a different path than I was including in my -isystem specifications. To solve this, I added

QMAKE_INCDIR_QT = 

to qmake.conf (in qt/mkspecs/unsupported/linux-clang/)

Since someone else on the project had fanangled qmake into using the project libraries everywhere else.

like image 165
Tsubashi Avatar answered Sep 18 '22 11:09

Tsubashi


For those who stumble upon this question with a more general problem than the author. Try inserting:

LIBS_USED_FOR_QT = QtCore QtSql QtMultimediaWidgets QtSensors QtSvg QtXml QtPrintSupport QtWidgets QtQuick QtQml QtPositioning QtGui QtWebKitWidgets
for(somelib, $$list($$LIBS_USED_FOR_QT)) {
    QMAKE_CXXFLAGS += -isystem $$(QTDIR)/lib/$${somelib}.framework/Versions/5/Headers/
    QMAKE_CXXFLAGS += -isystem $$(QTDIR)/lib/$${somelib}.framework/Headers/
}

in your .pro file. Addtionally avoid includes like #include <QtCore/QtCore> writing #include <QtCore> instead

This tamed qt quite efficiently for me.

see also this source

like image 30
Martin Avatar answered Sep 16 '22 11:09

Martin