This tutorial shows what to cross-compile the Embedded build of Qt 5.5 for Raspberry Pi 2. The Embedded build does not use the X11 server and instead displays the GUI directly using the Raspberry Pi framebuffer. We'll show how to use a Raspberry pi Cross-compiler to build the QT5 framework for Raspberry Pi in a Windows machine.
- Download a fresh SD card image for your Raspberry Pi. In this tutorial we'll use a Debian jessieimage. Write the image into the SD card using Winflashtool or any other similar tool.
- Download a cross-toolchain matching the image and install it:
- Download and install a MinGW toolchain that'll be used to build Windows versions of the build tools like Qmake:
- Download and install Python 2.7 for Windows and ensure, that it 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.
- Before we can build the Qt for Raspberry Pi, we need to resynchronize the sysroot with the toolchain to ensure that the to Olchain have all the headers and libraries from your Raspberry. Start the updatesysroot.bat file from the <sysgcc>\raspberry\tools folder:you need to synchronize at least The/opt folder, as it contains OpenGL headers that is not included in the toolchain. If you had installed additional packages on your Raspberry Pi, resynchronize other suggested directories as well.
- 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 Raspberry Pi Cross-compiler is added to PATH. If not, add them manually:
- Open the qt-everywhere-opensource-src-5.5.0\qtbase\mkspecs\linux-arm-gnueabi-g++\qmake.conf file and Replace all occurences of Arm-linux-gnueabi-with arm-linux-gnueabihf-:
- Now we is ready-to-build Qt. Due to a bug in the Qmake build script, we'll need to build it in 2 Steps:first we'll b Uild a Qmake for Windows and then we'll build the actual Qt binaries. First we'll modify the win32-g++ platform definition to prevent MinGW from excluding some functions the 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:
| 123 |
mkdir qt-build CD qt-build ../Qt-Everywhere-OpenSource-Src-5.5.0/Configure -PlatformWin32-G++ -XplatformLinux-Arm-Gnueabi-G++ -Release -OpenglEs2 -DeviceLinux-Rasp-Pi2-g++ - Sysroot c:/sysgcc/raspberry/arm-linux- gnueabihf/sysroot Span class= "Crayon-o" >-prefix /usr/local/ qt5 |
Note the "-opengl es2″option that configures Qt to use the Raspberry Pi framebuffer directly instead of the X11 system.
- Eventually the build should fail complaining about the errors to process specs for the raspberry device:
- The 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 Qmak E line "With this one:
| 1 |
if [ '! ' -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 |
< Span class= "Crayon-o" >-device-option cross_compile=c:/sysgcc/Raspberry/bin/arm -linux-gnueabihf< Span class= "Crayon-o" >- -qt -XCB |
The-device-option is required when using the device specification, however if you specify it while building Qmake, the Qt Build system would try to use the Cross-compiler to build the Windows Qmake executable that would obviously fail.
- Once the Configure script reports that's the configuration is complete, run the ' Make && make install ' command to BU ILD the entire QT framework and install it into the Cross-compiler directory. The framework is huge, and the build process might take several hours to complete and 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 buil T state failing further builds until the entire directory is deleted and re-created.
- Open Smartty (a portable version can be found in <sysgcc>\raspberry\tools\portablesmartty) and connect to your R Aspberry Pi. Then run the following commands to create The/usr/local/qt5 folder and make it writable to the current user:
Table class= "Crayon-table" > 123 cd /usr/local Span class= "crayon-e" >sudo mkdir qt5 sudo chown pi qt5
Then select Scp->upload Directory:
- Select the <SYSROOT>\USR\LOCAL\QT5 directory and upload it TO/USR/LOCAL/QT5:
- Wait for the upload to complete. The built Qt framework is relatively large and would take several minutes to upload:
- Once the upload is complete and you can test out the framework. Go to the/usr/local/qt5/examples/opengl/qopenglwidget directory and launch ./qopenglwidget:
- Look at the screen connected to the HDMI port of the Raspberry Pi. You'll see a rotating Qt logo animation:if The screen does don't show anything shut down your Raspberry Pi and re-plug th E power connector. As long as the screen was connected when the device was powered on, Raspberry Pi should recognize it.
Now so you had cross-compiled the QT framework for your Raspberry, follow this tutorial to create and build a basic Qt Application using the same cross-compiler.
http://visualgdb.com/tutorials/raspberry/qt/embedded/
Cross-compiling Qt Embedded 5.5 for Raspberry Pi 2