Raspberrypi beginners guide
Beginner’s guide to cross-compile Qt5 on RaspberryPi
Introduction
This is a step by step guide to help beginners to: cross-compile QT5 for RaspberryPi(wheezy), create, deploy and run an example project. This article will focus on simplicity, so if you are looking for additional customization, please check a more detailed guide [qt.io].
For an easy install, try this script. [gist.github.com]
Or get a later version here [gitorious.org]
For help, run
Getting Started
First we create a folder to hold the source code and all the required files to do the cross-compilation. We chose to create a directory named “opt” in the home folder:
Now, download the following files:
- Raspbian Wheezy image from (here [raspberrypi.org]):
And mount it:
- The toolchain built by Donald: (Note, seems to be dead links!)
Pro tip: don’t build your own cross-compiler. You’ll overlook something important and loose a couple of hours of your life for nothing. A suitable Raspberry Pi cross-compiler is also available here: https://github.com/raspberrypi/tools
It is a 32-bit build so if you are running on a 64-bit machine (you probably are) you need to install ia32-libs:
- Clone the cross-compile-tools repository:
- Clone and init the Qt5 repository:
If you’re behind a firewall ./init-repository might fail. First run this command:
Then retry:
- Finally, apply a patch on the qtjsbackend repository:
Compiling qtbase
Now the we have all the resources needed to compile qt5 for raspberry, we need to execute a script to fix symlinks and lib paths:
Go to the qt5/qtbase folder and run:
Note: if you want the qmlscene binary you should add -make tools to the ./configure command.
Compiling other modules
Now that you have qmake, you can cross-compile the other modules. To avoid dependencies errors, the following order is sugested:
qtimageformats, qtsvg, qtjsbackend, qtscript, qtxmlpatterns, qtdeclarative, qtsensors, qt3d, qtgraphicaleffects, qtjsondb, qtlocation, qtdocgallery.
To compile, you must do like the example below:
We have all the modules installed in the wheezy image, now we can copy it to the sdcard using dd:
obs: Check the entry point of your sdcard. Mine was /dev/sdb.
Notes for OSX
- Because your sdcard will be partitioned, OSX won’t let you umount it, so you’ll need to type:
where “disk3” will be the /dev/diskXsY where your sdcard first appeared.
- To perform dd you will need to use the *r*disk index, so if your sdcard is disk3 you will need to type:
Boot up your pi.
Configuring Qt Creator
To use Qt Creator properly, you must configure the “Qt Version” and “Tool Chains” sections.
Tool Chain Settings
go to Tools -> Options.. -> Build & Run -> Compilers tab.
click in “Add -> GCC”.
On “Compiler Path” set to “/home/<you>/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-g++”.
Name it “ARM GCC” or similar.
obs: Adjust it to your username.
Qt Version settings.
Now go to Tools -> Options.. -> Build & Run -> Qt Versions tab.
Click in “Add..” and choose you qmake for raspberry “/usr/local/qt5pi/bin/qmake”.
Note for OSX
- Because /usr is not visible by default, you first need to open a terminal and type:
- After you’ve completed the qmake selection, if you wish to make /usr invisible again, type the same command with a capital V :
Configure Linux Devices
Go to Tools -> Options… -> Devices -> Devices tab.
Add a new configuration setting a “Generic Linux Device”
Hostname or IP address is the IP of your raspberry
user is pi
password is raspberry
obs: if your not did change it.
Now you are ready to run your first Qt raspberry pi project.
Example Project
You can download a hello world project:
Open the project in Qt Creator and go to the Projects pane.
Click Manage Kits and then Add.
Fill in:
Name: Raspberry Pi
Device Type: Generic Linux Device
Device: Raspberry Pi
Compiler: ARM GCC
Debugger->Manage->Edit->”/home/<you>/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-gdb” (change your username)
Qt version: Qt 5.x.x (qt5pi)
Ok->Add Kit->Raspberry Pi
Then go to the “Rasperry Pi” kit tab->System Environment and add LD_LIBRARY_PATH which is set to /usr/local/qt5pi/lib
Now you can build and run your application from Qt Creator.
Troubleshooting
Qt version not properly installed
You need to keep the SD card image mounted during development!
If QtCreator still reports this after mounting the SD card image, then you may need to create the directories missing from
or whatever the mount path is (these will probably include bin, translations, and so on). You can create empty directories using the mkdir command.
The default mkspec symlink is broken.
It means that mkspec is not found on your sysroot, so your must copy it.
If the problem persists, create the missing symlink, e.g.
It is probably a good idea to do the same for the sysroot mkspecs.
Include <QtGui/QtGui>: No such file or directory
It seems Qt’s include was not found and you must add it to you .pro file:
Some people have seen this error. Adding the “-no-pch” option when running configure should prevent it.
Getting Could not determine the target architecture! and Could not determine the host architecture!
If you are getting this kind of error, it is possible that your current git branch is something other than master. To be sure, do the following:
If it shows like this:
Then you must checkout to master branch before running ./configure:
It is also good to fetch the latest commits and apply them by doing:
Also, check for the installation of libz (32 bits) in yor system. In ubuntu (64 bits) you might just:
After the ./configure script has failed first run these commands before restarting ./configure:
EGL Error : Could not create the egl surface: error = 0×3000
Try allocating more memory to video (try 64 or 128MB). Use the raspi-config utility to change this.
ABI detection failed
You will need Qt Creator 2.6 for Qt5 up to and including beta2.
Any Qt 5 later than that will need to use nightly snapshots (or will have to wait for Qt Creator 2.6.1): After the beta2 all libraries were renamed again.
See this forum thread for more details [qt.io]
./configure: 2654: ./configure: /home/<you>/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-g++: not found -reduce-exports was requested but this compiler does not support it
The error message is totally misleading. The real cause is that the precompile toolchain is 32-bit, so you need to:
make: g++: Command not found
Qt requires a native (non-cross-compiling) copy of g++ to be installed in order to build qmake. You can’t use clang. Fix with:
/mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/libdl.a(dlopen.o): In function `dlopen’: (.text+0xc): undefined reference to `__dlopen’
You need to run the ./fixQualifiedLibraryPaths again.
See: http://stackoverflow.com/questions/13626726/an-error-building-qt-libraries-for-the-raspberry-pi for more info.
Try adding -no-pch to the ./configure command line.
Cannot create forwarding script Betrete ‘qtactiveqt’.git/hooks/commit-msg: Datei oder Verzeichnis nicht gefunden
Try: