📜 ⬆️ ⬇️

We acquaint Qt with Raspberry Pi 3

Once there was a need to write programs for raspberry, namely using the wonderful QT framework, with all the conveniences of its creator. This article is an attempt to structure knowledge about building libraries and setting up an environment for convenient compilation and debug directly on hardware.

image


First of all, download the image of the system for raspberries. In my case, the raspbian jessie was at hand. Other distributions can be easily downloaded from the offsite . To make it easier to work at the build stage, create a directory in your home directory:

mkdir ~/pi_cross/ 

Throw back the image of the system and you can, in principle, immediately mount it to yourself, it is useful further:
')
 sudo mount -o loop,offset=70254592 ~/pi_cross/raspberry-embed.iso /mnt/rasp-pi-rootfs. 

To calculate this very offset we do:

So:
 elesar@elesar ~ $ fdisk -l ~/pi_cross/raspberry-embed.iso Disk /home/elesar/pi_cross/raspberry-embed.iso: 16.0 GB, 16021192704 bytes 255 heads, 63 sectors/track, 1947 cylinders, total 31291392 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xb0358c95 Device Boot Start End Blocks Id System /home/elesar/pi_cross/raspberry-embed.iso1 8192 137215 64512 c W95 FAT32 (LBA) /home/elesar/pi_cross/raspberry-embed.iso2 137216 31291391 15577088 83 Linux 

We look at the end of the second part, and multiply by the size of the sector: 137216 * 512 = 70254592.

The next step is to copy the Qt sources:

 git clone git://code.qt.io/qt/qt5.git 

And, going to the freshly downloaded directory:

 cd qt5 

execute:

 ./init-repository 

to resume required submodules. This is where we need coffee. My jump took at least half an hour. Then we need a cross-platform toolchain. It can be pulled from here:

 wget https://www.dropbox.com/s/sl919ly0q79m1e6/gcc-4.7-linaro-rpi-gnueabihf.tbz 

Unpack it in our daddy. You will also need a library:

 sudo apt-get install ia32-libs 

But only if you have 64 bit OS. Now that everything has been downloaded, and a new batch of coffee is on its way, you can run a useful script from the toolchain:

 sudo ./fixQualifiedLibraryPaths /mnt/rasp-pi-rootfs/ ~/pi_cross/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-gcc 

Which will set up the symlinks. Everything, now it is possible to start assembly of Qt. Go to the configurator:

 cd ~/pi_cross/qt5/qtbase 

And we perform:

 ./configure -qt-xcb -openssl -securetransport -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=~/pi_cross/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf- -sysroot /mnt/rasp-pi-rootfs -opensource -confirm-license -optimized-qmake -reduce-exports -release -qreal float -make libs -prefix /usr/local/qt5pi -hostprefix /usr/local/qt5pi 

To which the terminal will respond in a friendly way, something like this:

image

Listing supported options. We collect:

 make -j 4 sudo make install 

This is the longest stage. My typewriter rustled baikikami about an hour. Everything is almost ready. The exhaust assembly-installation is the disk image, which we have mounted ahead of time. It must be unmounted and poured onto the SD card, which must be inserted into Malinka and can be turned on. (fotochka rab.stola Malinki).

After loading the system and a small configuration, we begin to configure Creator. To begin with, we’ll tell qmake that it was built, like a Frankenstein, in the / usr / local / qt5pi / bin / qmake folder:

image

We specify gcc-4.7-linaro-rpi-gnueabihf / bin / arm-linux-gnueabihf-gcc as the compiler:

image

Create a device, give it a password and address:

image

Create a new kit with the appropriate name:

image

In sysroot we specify our newly mounted image. The only catch is debugger. I flatly refused to work as such from linaro, so I slipped GDB-Multi, which works without complaints. Everything! Now, when creating a new project, a new set has become available:

image

To run and debug directly on the device, you need to add a couple of lines to the .pro file:

 target.path = /usr/bin INSTALLS += target TARGET = Name_On_Target 

They will indicate the way in which the application is installed, and its name.

As a conclusion, I would like to note a minus of such a method - for any changes on the target, for example, installing new libraries, you have to remove the image from the SD card in order to mount it as a sysroot, otherwise the compiler will not know about them. Thank you for your attention, I bow away. And bypass you by the side of the exceptions.

Source: https://habr.com/ru/post/357960/


All Articles