Wednesday, February 2, 2022

[SOLVED] Unable to cross-compile Qt 5.14.2 for Raspberry PI zero w because it “requires a C++11 compiler”

Issue

This problem has already been encountered for previous versions of Qt5 : Stack-overflow post (non-answered yet). I'm having the same problem with a more recent version and I have followed several tutorials online :

Even if all these tutorials are outdated, the methodology for cross compiling Qt5 stays the same. My target board is a Raspberry pi zero w running Raspbian Buster. The configuration steps have worked fine (there weren't any errors).

I'm getting the following errors while executing make :

~/Documents/Raspbian/raspi/qt-everywhere-src-5.14.2/qtbase/include/QtCore/../../src/corelib/thread/qbasicatomic.h:61:4: error: #error "Qt requires C++11 support"
 #  error "Qt requires C++11 support"
    ^
~/Documents/Raspbian/raspi/qt-everywhere-src-5.14.2/qtbase/include/QtCore/../../src/corelib/thread/qbasicatomic.h:94:13: error: ‘QAtomicOps’ does not name a type
     typedef QAtomicOps<T> Ops;
             ^
In file included from ~/Documents/Raspbian/raspi/qt-everywhere-src-5.14.2/qtbase/include/QtCore/qglobal.h:1:0,
                 from ~/Documents/Raspbian/raspi/qt-everywhere-src-5.14.2/qtbase/src/corelib/global/qt_pch.h:56:
~/Documents/Raspbian/raspi/qt-everywhere-src-5.14.2/qtbase/include/QtCore/../../src/corelib/thread/qbasicatomic.h:97:23: error: ‘QAtomicOpsSupport’ was not declared in this scope
     Q_STATIC_ASSERT_X(QAtomicOpsSupport<sizeof(T)>::IsSupported, "template parameter is an integral of a size not supported on this platform");
                       ^
~/Documents/Raspbian/raspi/qt-everywhere-src-5.14.2/qtbase/include/QtCore/../../src/corelib/global/qglobal.h:121:68: note: in definition of macro ‘Q_STATIC_ASSERT_X’
 #  define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
                                                                    ^
~/Documents/Raspbian/raspi/qt-everywhere-src-5.14.2/qtbase/include/QtCore/../../src/corelib/thread/qbasicatomic.h:97:51: error: ‘::IsSupported’ has not been declared
     Q_STATIC_ASSERT_X(QAtomicOpsSupport<sizeof(T)>::IsSupported, "template parameter is an integral of a size not supported on this platform");
                                                   ^
~/Documents/Raspbian/raspi/qt-everywhere-src-5.14.2/qtbase/include/QtCore/../../src/corelib/global/qglobal.h:121:68: note: in definition of macro ‘Q_STATIC_ASSERT_X’
 #  define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
                                                                    ^
~/Documents/Raspbian/raspi/qt-everywhere-src-5.14.2/qtbase/include/QtCore/../../src/corelib/global/qglobal.h:121:49: error: non-constant condition for static assertion
 #  define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
                                                 ^
~/Documents/Raspbian/raspi/qt-everywhere-src-5.14.2/qtbase/include/QtCore/../../src/corelib/thread/qbasicatomic.h:97:5: note: in expansion of macro ‘Q_STATIC_ASSERT_X’
     Q_STATIC_ASSERT_X(QAtomicOpsSupport<sizeof(T)>::IsSupported, "template parameter is an integral of a size not supported on this platform");
     ^
~/Documents/Raspbian/raspi/qt-everywhere-src-5.14.2/qtbase/include/QtCore/../../src/corelib/thread/qbasicatomic.h:97: confused by earlier errors, bailing out
make[3]: *** [Makefile:1836: .pch/Qt5Core.gch/c++] Error 1
make[3]: Leaving directory '~/Documents/Raspbian/raspi/qt5build/qtbase/src/corelib'
make[2]: *** [Makefile:228: sub-corelib-make_first] Error 2
make[2]: Leaving directory '~/Documents/Raspbian/raspi/qt5build/qtbase/src'
make[1]: *** [Makefile:51: sub-src-make_first] Error 2
make[1]: Leaving directory '~/Documents/Raspbian/raspi/qt5build/qtbase'
make: *** [Makefile:88: module-qtbase-make_first] Error 2

Solution

The compiler you're using is just too old. The verison you're getting from the link you shared is 4.8.3, whereas you'll need at least gcc 5. (Check here: https://codereview.qt-project.org/c/qt/qtdoc/+/288825)

The Error you get might be a bit misleading, since gcc itself states that it fully supports C++11 from 4.8.1 as stated here: https://gcc.gnu.org/projects/cxx-status.html#cxx11

I propose u use a more up to date version of gcc. As mentioned within the qt-docs, it should be at least gcc version 5 or higher.

There are several ways for you to et one (ordered from simple to more complicated):

  1. Try to use the package manager of your system (e.g. sudo apt install gcc-arm-linux-gnueabihf)
  2. Download one somewhere else. (e.g. here: https://toolchains.bootlin.com/)
  3. Build your own. (maybe use crosstool-ng). But be aware! that might be tricky. even though I've good experiences using crosstool-ng, or tools alike.

Last but not least, don't forget to change the setting of your ./configure step! Pinpoint to the new toolchain you're trying to use.

Kind Regards



Answered By - 3.141592
Answer Checked By - Mildred Charles (WPSolving Admin)