From 605062b21fccff919b7894db91b197d120e528f6 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 10 Jul 2019 08:16:56 +0200 Subject: [PATCH] Fix MinGW cross-build with precompiled headers on Linux We need localtime_r() in several places. To have this function declared when including time.h, _POSIX_THREAD_SAFE_FUNCTIONS must be defined. E.g. qdatetime.cpp includes unistd.h before time.h to define said macro. However, this falls apart when precompiled headers are used, because of the following include chain in qt_pch.h: qcoreapplication.h -> qobject.h -> chrono -> time.h This patch ensures that _POSIX_THREAD_SAFE_FUNCTIONS is defined before including time.h in qt_pch.h by including unistd.h early. Fixes: QTBUG-76680 Change-Id: I3875072edf37f45492f29d84fc297a9682e11db4 Reviewed-by: Oliver Wolff Reviewed-by: Friedemann Kleint --- src/corelib/global/qt_pch.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/corelib/global/qt_pch.h b/src/corelib/global/qt_pch.h index 3972991618..0dfd6c745f 100644 --- a/src/corelib/global/qt_pch.h +++ b/src/corelib/global/qt_pch.h @@ -55,6 +55,10 @@ #include #include #ifdef Q_OS_WIN +# ifdef Q_CC_MINGW +// must be included before any other header pulls in . +# include // Define _POSIX_THREAD_SAFE_FUNCTIONS to obtain localtime_r() +# endif # define _POSIX_ # include # undef _POSIX_