简体   繁体   中英

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

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

For future readers as pointed out the cross compiler provided by: https://github.com/raspberrypi/tools is outdated and cannot be used. I have tried all the methods described above but the one that worked out-of-the-box (for Raspberry Pi 0 W which is based on older ARMv6 architecture) is: https://github.com/Pro/raspi-toolchain This repo provides a Docker image that compiles a newer toolchain from source and even provides a test code that you can cross compile using the generated toolchain and execute on the pi.

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 (eg sudo apt install gcc-arm-linux-gnueabihf)
  2. Download one somewhere else. (eg 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

I had the same issue.

I ended up with proper cross compilation of Qt 5.15.0 with EGL support only (to avoid using X11 on such tiny Rpi zero) with the following actions:

1- As proposed by @glamis, I used the compilation toolchain from: https://github.com/Pro/raspi-toolchain via the pre-built toolchain in release v1.0.1

2- (crappy) hacked in Qt sources qtdeclarative/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp : I replaced the constant PATH_MAX (not present in this toolchain?) by hardcoded value 4096

3- still in Qt sources, edit the file qtbase/mkspecs/devices/linux-rasp-pi-g++/qmake.conf

3.a) replace all occurrences of -lEGL -lGLESv2 -lOpenVG by -lbrcmEGL -lbrcmGLESv2 -lbrcmOpenVG

3.b) move QMAKE_LIBS_OPENGL_ES2 = -lbrcmGLESv2 -lbrcmEGL outside the if statement to force it in all cases

notes:

  • raspberry pi zero, with "Raspberry Pi OS Lite" (aka. raspbian Lite) version, based on debian buster, version 2020-05-27

  • dependencies installed: apt install build-essential libfontconfig1-dev libdbus-1-dev libfreetype6-dev libicu-dev libinput-dev libxkbcommon-dev libsqlite3-dev libssl-dev libpng-dev libjpeg-dev libglib2.0-dev libgbm-dev libraspberrypi-dev libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0

  • qt archive used: qt-everywhere-src-5.15.0.tar.xz

  • my configure looks like: configure -release -opensource -confirm-license -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=/opt/cross-pi-gcc/bin/arm-linux-gnueabihf- -sysroot $HOME/rpi/rootfs -prefix /usr/local/qt-5.15.0-rpi -extprefix $HOME/rpi/qt-5.15.0-rpi -hostprefix $HOME/rpi/tools -make libs -no-use-gold-linker -skip qtwayland -skip qtlocation -skip qtscript -v -no-gbm -ssl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM