@@ -0,0 +1,375 @@
# QT-Raspi Cross Compile
## Prepare the Raspberry Pi:
### Install raspbian
Get the latest raspbian image [ here] ( https://www.raspberrypi.org/downloads/raspbian/ )
### Enable deb-src repos
Uncomment the ` deb-src ` line in ` /etc/apt/sources.list ` and update raspbian
``` bash
sudo nano /etc/apt/sources.list
```
``` bash
sudo apt-get update
sudo apt-get upgrade
sudo shutdown -r now
```
### Update Raspberry Pi firmware
``` bash
sudo rpi-update
sudo shutdown -r now
```
### Run raspi-config
change the GPU memory to ` 256MB ` and boot with ` "wait for network on boot" `
``` bash
sudo raspi-config
```
> (Optional) Install and configure touch-screen display.
### Install dependencies
``` bash
sudo apt-get build-dep qt4-x11
sudo apt-get build-dep libqt5gui5
sudo apt-get install libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0
sudo apt-get install cmake
```
#### Optional
##### Bluetooth
``` bash
sudo apt-get install bluez libbluetooth-dev
```
##### Audio & gstreamer multimedia
``` bash
sudo apt-get install libasound2-dev pulseaudio libpulse-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-plugins-bad libgstreamer-plugins-bad1.0-dev gstreamer1.0-pulseaudio gstreamer1.0-tools gstreamer1.0-alsa
```
#### Printing support
``` bash
sudo apt-get install libcups2-dev
```
#### Accessibility
``` bash
sudo apt-get install libatspi-dev
```
### ** (Skip this)** Fix the EGL/GLES libraries
Create correct symlinks to "missing" libraries
``` bash
sudo mv /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0_backup
sudo mv /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0 /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0_backup
sudo ln -s /opt/vc/lib/libEGL.so /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0
sudo ln -s /opt/vc/lib/libGLESv2.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0
```
Please make sure to also add missing symbolic links
``` bash
sudo ln -s /opt/vc/lib/libEGL.so /opt/vc/lib/libEGL.so.1
sudo ln -s /opt/vc/lib/libGLESv2.so /opt/vc/lib/libGLESv2.so.2
```
### Install mysql c connector from source
Download mysql c connector source from [ here] ( https://downloads.mysql.com/archives/c-c/ ) `(Source code, Generic Linux (Arsitecture Independent))
`
> i will install it on /opt/local/mysql-rpi-src
``` bash
tar zxvf mysql-connector-c-6.1.11-src.tar.gz
cd mysql-connector-c-6.1.11-src
cmake -G " Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/opt/local/mysql-rpi-src
make
sudo make install
```
### Prepare our target directory
``` bash
sudo mkdir /usr/local/qt5pi
sudo chown pi:pi /usr/local/qt5pi
```
## Prepare Linux host:
I use Ubuntu x64 and Qt 5.10.1
### Update host
``` bash
sudo apt-get update
sudo apt-get -y upgrade
```
### Install dependencies
``` bash
sudo apt-get install git bison python gperf
```
### Generate ssh public key
``` bash
ssh-keygen -t rsa
ssh-copy-id pi@< raspi ip>
```
> change ` <raspi ip> ` address of Raspberry Pi
### Create Working directory
``` bash
sudo mkdir /opt/raspi
sudo chmod a+w /opt/raspi
cd /opt/raspi
```
### Get a toolchain
``` bash
git clone https://github.com/raspberrypi/tools
```
Add toolchain binary directory to PATH.
Open .bashrc
``` bash
nano ~ /.bashrc
```
and add line at end of file
``` bash
export PATH=$PATH :/opt/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
```
update bashrc
``` bash
source ~ /.bashrc
```
### Create a sysroot
Using ` rsync ` we can properly keep things synchronized in the future as well
``` bash
mkdir -p sysroot/{opt,usr}
rsync -avz pi@< raspi ip> :/lib sysroot
rsync -avz pi@< raspi ip> :/usr/include sysroot/usr
rsync -avz pi@< raspi ip> :/usr/lib sysroot/usr
rsync -avz pi@< raspi ip> :/opt/vc sysroot/opt
rsync -avz pi@< raspi ip> :/opt/local sysroot/opt/
```
Also copy mysql-rpi-src to host /opt
This use for ` ./configure ` flag: ` MYSQL_PREFIX=/opt/local/mysql-rpi-src `
``` bash
rsync -avz pi@< raspi ip> :/opt/local /opt/
```
> change ` <raspi ip> ` address of Raspberry Pi
### Fix the EGL/GLES libraries
Create correct symlinks to "missing" libraries
``` bash
mv sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0_backup
mv sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0 sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0_backup
ln -s sysroot/opt/vc/lib/libEGL.so sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0
ln -s sysroot/opt/vc/lib/libGLESv2.so sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0
```
Please make sure to also add missing symbolic links
``` bash
ln -s sysroot/opt/vc/lib/libEGL.so sysroot/opt/vc/lib/libEGL.so.1
ln -s sysroot/opt/vc/lib/libGLESv2.so sysroot/opt/vc/lib/libGLESv2.so.2
```
### Adjust symlinks to be relative
Use provided script, because the old fixQualifiedLibraryPaths is not working properly
``` bash
wget https://raw.githubusercontent.com/riscv/riscv-poky/priv-1.10/scripts/sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot
```
### Create build dir
#### use Qt source
``` bash
wget https://download.qt.io/official_releases/qt/5.10/5.10.1/single/qt-everywhere-src-5.10.1.tar.xz
```
and extract it
``` bash
tar Jxvf qt-everywhere-src-5.10.1.tar.xz
```
Create hf configuration
``` bash
cp -rv qt-everywhere-src-5.10.1/qtbase/mkspecs/linux-arm-gnueabi-g++ qt-everywhere-src-5.10.1/qtbase/mkspecs/linux-arm-gnueabihf-g++
sed -i -e ' s/arm-linux-gnueabi-/arm-linux-gnueabihf-/g' qt-everywhere-src-5.10.1/qtbase/mkspecs/linux-arm-gnueabihf-g++/qmake.conf
```
Create dir
``` bash
mkdir qt5build
cd qt5build
```
Configure Qt
``` bash
../qt-everywhere-src-5.10.1/configure -opengl es2 -device linux-rasp-pi3-g++ -device-option CROSS_COMPILE=arm-linux-gnueabihf- -sysroot /opt/raspi/sysroot -prefix /usr/local/qt5pi -opensource -confirm-license -plugin-sql-mysql MYSQL_PREFIX=/opt/local/mysql-rpi-src -recheck-all -skip qtwebengine -skip qtscript -make libs -no-use-gold-linker -v
```
If you failed, you can delete ` qt5build ` directory and try again
``` bash
cd ..
rm -rvf qt5build
```
#### use qtbase
``` bash
git clone git://code.qt.io/qt/qtbase.git -b < qt-version>
cd qtbase
```
> change ` <qt-version> ` with a proper Qt version
> I use 5.10; Note that version 5.10.1 is a tag not a branch,
> so you may want to create a local branch with it
Configure Qt
``` bash
./configure -opengl es2 -device linux-rasp-pi3-g++ -device-option CROSS_COMPILE=arm-linux-gnueabihf- -sysroot /opt/raspi/sysroot -prefix /usr/local/qt5pi -opensource -confirm-license -plugin-sql-mysql MYSQL_PREFIX=/opt/local/mysql-rpi-src -recheck-all -skip qtwebengine -skip qtscript -make libs -no-use-gold-linker -v
```
If you failed, you can clear everything with:
``` bash
git clean -dfx
```
##### Notes
> Sadly QtWebengine dont compile on Raspberry Pi 1 (maybe also Pi 2), so we have to skip it. Also skip QtScript, its deprecated.
```
For every version of Raspberry Pi, you have to change -device
Raspberry Pi 1 (+ Zero and Zero W): -device linux-rasp-pi-g++
Raspberry Pi 2: -device linux-rasp-pi2-g++
Raspberry Pi 3: -device linux-rasp-pi3-g++
Raspberry Pi 3 with VC4 driver: -device linux-rasp-pi3-vc4-g++
```
### Make and Install Qt
You probably also want to add ` -jn ` option to make command, where ` n ` is a number of cores you like to use for the complication
``` bash
make
make install
```
### Deploy Qt to the device
We simply sync everything from /opt/raspi/sysroot/usr/local/qt5pi to the prefix we configured above
``` bash
cd /opt/raspi
rsync -avz sysroot/usr/local/qt5pi pi@< raspi ip> :/usr/local
```
> change ` <raspi ip> ` address of Raspberry Pi
## Qt configuration
Once Qt is on the device, Qt Creator can be set up to build, deploy, run and debug Qt apps directly on the device with one click.
```
Go to Options -> Devices
Add
Change the name
Generic Linux Device
Enter IP address
authentication type key
user & add private key ( ~/.ssh/id_rsa )
Finish
```
```
Go to Options -> Build&Run -> Debuggers
Add
/opt/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gdb
```
```
Go to Options -> Build&Run -> Compilers
Add
GCC -> C++
Compiler path: /opt/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
ABI: arm - linux - generic - elf - 32bit
Add
GCC -> C
Compiler path: /opt/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc
ABI: arm - linux - generic - elf - 32bit
```
```
Go to Options -> Build&Run -> Qt Versions
Add
/opt/raspi/sysroot/usr/local/qt5pi/bin/qmake
```
```
Go to Options -> Build & Run -> Kits
Add
Change the name & icon
Device type: Generic Linux Device
Device: the one we just created
Sysroot: ~/raspi/sysroot
Compiler: the one we just created
Debugger: the one we just created
Qt version: the one we saw under Qt Versions
Qt mkspec: leave empty
```
Done. At this point you should be able to start a new project with the new kit, build and deploy it, etc.
If you press compile Button inside QtCreator, source will just compile.
If you press the green Play button, source will compile, upload binary with sftp and executed on your Raspberry Pi.
Debug button should also work