Search code examples
c++qmake

QMake: sudden conflict between system and project headers


While switching from gcc 6 to gcc 8 a Qt project stopped to compile with following error being the culprit:

In file included from /usr/include/qt4/QtCore/qstring.h:46,
                 from /usr/include/qt4/QtCore/QString:1,
                 from ../common/strings.h:11,
                 from /usr/include/string.h:431,
                 from /usr/include/qt4/QtCore/qlist.h:60,
                 from /usr/include/qt4/QtCore/qhash.h:48,
                 from /usr/include/qt4/QtCore/qdebug.h:46,
                 from /usr/include/qt4/QtCore/QtDebug:1,
                 from src/main.h:26,
                 from ../common/main.cpp:9:
/usr/include/qt4/QtCore/qbytearray.h:531:13: note: previous declaration ‘bool operator==(const char*, const QByteArray&)’
 inline bool operator==(const char *a1, const QByteArray &a2)

The reason of such error is that the legacy header file from project ../common/strings.h is included from system header /usr/include/string.h. In .pro file include paths are listed like this and were not changed.

 INCLUDEPATH += . \
               ../common
           

In both cases /usr/include/string.h contains #include <strings.h>. Why problem doesn't surface while using older versions of GCC?


Solution

  • Header strings.h is now a part of system interfaces: https://man7.org/linux/man-pages/man0/strings.h.0p.html

    The problem was actually that OS itself was newer, not the GCC. An unintentional use of deprecated -I on a location of a header matching by name a system one is a recipe for disaster.