Cross-compiling Qt 5.5 for Beaglebone-Debian
This tutorial shows how to cross-compile the Qt 5.5 framework for Beaglebone-Debian. We will build the X11-based version of Qt for the Beaglebone Black board.
Warning: Modern Beaglebone Debian distributions include a pre-built version of Qt that can be used by VisualGDB out-of-the-box. Follow this tutorial to create a cross-compiled Qt5 app based on the pre-built Qt package. The rest of this tutorial demonstrates building of the Qt framework from scratch that can be useful if you need specific Qt configuration that is different from the default package.
- Download an SD card image to your Beaglebone and get a matching cross-toolchain:
- Download and install a MinGW toolchain that will be used to build the Windows-side build tools like Qmake:
- Download and install Python 2.7 for Windows and ensure that its directory is added to PATH.
- Download the Qt source package (e.g. qt-everywhere-opensource-src-5.5.0.tar.xz) from the Qt Archive.
- If you installed additional packages to your Beaglebone, you will need to resynchronize the sysroot with the toolchain to ensure that the toolchain has all the headers and libraries from your Beaglebone. Start the UpdateSysroot.bat file from the <sysgcc>\Beaglebone\TOOLS folder and synchronize the suggested directories.
- Launch the msys shell from the MinGW toolchain by running<sysgcc>\MinGW32\msys\1.0\msys.bat:
- Go to the directory containing the archive with the Qt source and extract it by running tar xf <archive name>:
- Ensure that the directories containing the MinGW gcc compiler and the Beaglebone cross-compiler are added to PATH. If not, add them manually:Ensure the the default ‘make’ executable is the one from the MinGW build folder. If not, add the /bin folder to the beginning of PATH.
- Now we will edit the device configuration file to fix the build and enable X11 as the default GUI platform for Qt. Comment out the “-mfloat-abi” setting and change QT_QPA_DEFAULT_PLATFORM to xcb:
- Now we are ready to build Qt. Due to a bug in the Qmake build script, we will need to build it in 2 steps: first we will build a Qmake for Windows and then we’ll build the actual Qt binaries. First we will modify the win32-g++ platform definition to prevent MinGW from excluding some functions that Qt relies upon. Open the qt-everywhere-opensource-src-5.5.0\qtbase\mkspecs\win32-g++\qmake.conf file and add -U__STRICT_ANSI__ to CXXFLAGS:
- Now we can build the Windows tools. Create a directory (e.g. qt-build) and run the configuration script from there:
123mkdir qt-buildcd qt-build../qt-everywhere-opensource-src-5.5.0/configure -platform win32-g++ -xplatform linux-arm-gnueabi-g++ -release -device linux-beagleboard-g++ -sysroot C:/SysGCC/Beaglebone/arm-linux-gnueabihf/sysroot -prefix /usr/local/qt5
- Eventually the build should fail complaining about the errors to process specs for the Beaglebone device. This is normal as long as qmake.exe got built. Check this by running “qtbase/bin/qmake -v”:
- Now we can build the rest of the Qt framework. First of all open the qtbase\configure file and replace the condition before the “Creating qmake line” with this one:
1if [ '!' -f "$outpath/bin/qmake.exe" ]; then
- Start the configure script again, this time adding the following argument to the end of the previous command line:
1-device-option CROSS_COMPILE=C:/SysGCC/Beaglebone/bin/arm-linux-gnueabihf- -qt-xcb
The -device-option is required when using the device specification, however if you specify it while building Qmake, the Qt build system will try to use the cross-compiler to build the Windows Qmake executable that will obviously fail.
- Once the configure script reports that the configuration is complete, run the “make && make install” command to build the entire Qt framework and install it into the cross-compiler directory. The framework is huge, so the build process might take several hours to complete, even on a fast machine.Warning: do not run “make install” before “make” succeeds as it would fail leaving the build directory in a partially built state failing further builds until the entire directory is deleted and re-created.
- Open SmarTTY (a portable version can be found in <SysGCC>\Beaglebone\TOOLS\PortableSmartty) and connect to your Beaglebone. Then run the following commands to create the /usr/local/qt5 folder and make it writable to the current user:
123cd /usr/localsudo mkdir qt5sudo chown pi qt5
- Then select SCP->Upload directory and upload the <sysroot>\usr\local\qt5 directory to /usr/local/qt5:
- Go to the /usr/local/qt5/examples/widgets/dialogs/classwizard directory and run ./classwizard:
- If Qt complains about missing QT_XKB_CONFIG_ROOT variable and the keyboard does not work, you can define it by running the following command:
- Then the example will start normally (the QXcbConnection error can be ignored):
- You will see the Qt class wizard window forwarded from the remote machine:Follow this tutorial to learn how to create Qt projects for Beaglebone-Debian with Visual Studio.