QT 5.10 cross compile for Odroid-XU4

Post Reply
Posts: 16
Joined: Thu Jul 25, 2019 4:09 pm
languages_spoken: english
ODROIDs: Odroid-XU4
Has thanked: 0
Been thanked: 8 times

QT 5.10 cross compile for Odroid-XU4

Post by jaf_kh »

QT 5.10 cross compile for Odroid-XU4:
This is "How I do it" to cross compile QT 5.10.0 for Odroid-XU4.
Host PC: Ubuntu 16 (18 may be good) with 8GB RAM (at least) and 30GB free disk space
Odroid-XU4 with Ubuntu mate 18.04
QT 5.10 source code
Updated cross compiler
A lot of patience

1. Very important, Prepare Host Ubuntu PC :
Increase RAM to at least 8GB to compile WebEngine (very intensive and memory hungry)
Enable swap with at least 2GB
Free harddisk space required at least 30GB (more is better)
Upgrade some components, then install the following requirements (may need to append --fix-missing)
Also Enable all sources and select good mirror in Software and Update Setting

Code: Select all

sudo apt-get update
sudo apt upgrade
sudo reboot
upgrade gcc compiler to latest gcc (7.4),see: http://tuxamito.com/wiki/index.php/Inst ... _in_Ubuntu

Install some requirements:

Code: Select all

sudo apt-get install build-essential libfontconfig1-dev libdbus-1-dev libfreetype6-dev libicu-dev libsqlite3-dev libssl-dev libpng12-dev libjpeg9-dev libglib2.0-dev
sudo apt-get install gperf
sudo apt-get install bison flex ruby python

sudo apt-get install libasound2-dev libbz2-dev libcap-dev 
sudo apt-get install libcups2-dev libdrm-dev libegl1-mesa-dev libgcrypt11-dev libpci-dev libpulse-dev libudev-dev 
sudo apt-get install libxtst-dev gyp ninja-build
the following lines are very important to install some dependencies at host machine: /usr/include/sys, /usr/include
Enable i386 architecture on Linux 64:

Code: Select all

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get dist-upgrade

sudo apt-get install libc6-dev-amd64
sudo apt-get install gcc-multilib g++-multilib
sudo apt-get install gcc-5-multilib g++-5-multilib
sudo apt-get install gcc-7-multilib g++-7-multilib

sudo apt-get install libstdc++6:i386 libncurses5:i386 libz1:i386 libc6:i386 libc6-dev-i386
Note: qtwebengine requires 32-bit compiler to be compiled for Arm, since we have 64-bit machine, we have to install 32-bit libraries and headers for c++/gcc

2. Prepare an eMMC or SD with XU4 Ubuntu 18.04, put it on the target board
from XU4 board run:

Code: Select all

sudo apt-get update
sudo apt upgrade
sudo reboot

sudo apt-get build-dep qt5-default qt5-qmake
sudo apt-get install libiconv-hook-dev libinput-dev libts-dev bluez libbluetooth-dev libgstreamer1.0-dev libegl1-mesa libegl1-mesa-dev
sudo apt-get install "^libxcb.*" libx11-xcb-dev libglu1-mesa-dev libxrender-dev
required by webengine:

Code: Select all

sudo apt-get install libnss3-dev
sudo apt-get install bison build-essential gperf flex ruby python libasound2-dev libbz2-dev libcap-dev \
libcups2-dev libdrm-dev libegl1-mesa-dev libgcrypt11-dev libpci-dev libpulse-dev libudev-dev \
libxtst-dev gyp ninja-build

sudo apt-get install libssl-dev libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev \
libfontconfig1-dev libxss-dev libsrtp0-dev libwebp-dev libjsoncpp-dev libopus-dev libminizip-dev \
libavutil-dev libavformat-dev libavcodec-dev libevent-dev

sudo apt-get install libstdc++6
(required to prevent compiler linking with old Qt 5 libraries)

Code: Select all

sudo apt-get remove libqt5*   
Also, on the Ordroid-XU4 device, run the following commands to fix some broken links and add symbolic links to EGL driver:

Code: Select all

sudo rm /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0
sudo rm /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2
sudo rm /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0
sudo ln -s /usr/lib/arm-linux-gnueabihf/mali-egl/libmali.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0
sudo ln -s /usr/lib/arm-linux-gnueabihf/mali-egl/libmali.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2
sudo ln -s /usr/lib/arm-linux-gnueabihf/mali-egl/libmali.so /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0

sudo rm /usr/lib/arm-linux-gnueabihf/mali-egl/libGLESv2.so.2
sudo rm /usr/lib/arm-linux-gnueabihf/mali-egl/libGLESv2.so.2.0
sudo ln -s /usr/lib/arm-linux-gnueabihf/mali-egl/libmali.so /usr/lib/arm-linux-gnueabihf/mali-egl/libGLESv2.so.2.0
sudo ln -s /usr/lib/arm-linux-gnueabihf/mali-egl/libmali.so /usr/lib/arm-linux-gnueabihf/mali-egl/libGLESv2.so.2
sudo ln -s /usr/lib/arm-linux-gnueabihf/mali-egl/libmali.so /usr/lib/arm-linux-gnueabihf/mali-egl/libEGL.so.1.0.0
sudo ln -s /usr/lib/arm-linux-gnueabihf/mali-egl/libmali.so /usr/lib/libGLESv2.so.2
sudo ln -s /usr/lib/arm-linux-gnueabihf/mali-egl/libmali.so /usr/lib/libEGL.so.1

3. Shutdown board and move SD to SD reader and put on Host PC, assuming the SD is sdb on Linux

4. use gparted to reduce the SD size by unallocating the free space, unmount sdb2 first, then resize it (8GB to 10GB is fine) and apply changes
On Windows PC:
use Win32DiskImager to create compact image (Read only allocated sectors) and copy the generated iso image to desktop ubuntu. The image name is xu4.img

5. On the Host ubuntu, display xu4.img information:

Code: Select all

sudo fdisk -l xu4.img

Disk xu4.img: 10.4 GiB, 11194596864 bytes, 21864447 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
Disklabel type: dos
Disk identifier: 0x3cedfd53

Device     Boot  Start      End  Sectors  Size Id Type
xu4.img1          2048   264191   262144  128M  c W95 FAT32 (LBA)
xu4.img2        264192 21864447 21600256 10.3G 83 Linux
Check the start offset of second partition (rootfs) and multiply by 512 (264192 *512)= 135266304
IMPORTANT: make sure you have enough disk space

Code: Select all

sudo mkdir /mnt/odroid.img
sudo mount ./xu4.img -o loop,offset=$((512*264192)) /mnt/odroid.img/

Note: you need to mount the image each time you use the Qt creator

6. make mounted image as symbolic, on the host ubuntu:

Code: Select all

wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
chmod a+x sysroot-relativelinks.py

sudo ./sysroot-relativelinks.py /mnt/odroid.img/
7.Download QT 5.10.0, download qt-opensource-linux-x64-5.10.0.run
transfer it to Ununtu home directory and make it executable and run it,
Select to install only Source to ~/Qt5.10.0
It will be installed to /home/username/Qt5.10.0/5.10.0/Src

Correct mali issue on qt5 source code:
Edit a file for correct detecting the ARM's Mali GPU.
Line 86 : /home/username/Qt5.10.0/5.10.0/Src/qtbase/src/platformsupport/eglconvenience/qxlibeglintegration.cpp
from : if (vendor && strstr(vendor, "Vivante")) {
to : if (vendor && (strstr(vendor, "Vivante") || strstr(vendor, "ARM"))) {

8. On the host ubuntu

Code: Select all

mkdir ~/Odroid
cd Odroid
also download Linaro gnu cross compiler 7.4.1
Unpack Linaro cross compiler and place inside /hpme/username/Odroid to create a directory /home/ggg/Odroid/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf
Linaro releases are found here: https://releases.linaro.org/components/ ... /binaries/:

Code: Select all

wget https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/arm-linux-gnueabihf/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz 
tar xf gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz
Note: this compiler is newer than RPi toolchain

9. Adjust device config file
The shipped "qmake.conf" file of device odroid-xu3-g++ will not pass configuration stage due to missing lines,
This file is found at /home/username/Qt5.10.0/5.10.0/Src/qtbase/mkspecs/devices/linux-odroid-xu3-g++
Edit this file as follows:

Code: Select all


# qmake configuration for linux-odroid-xu3-g++ using the arm-linux-gnueabihf-g++ crosscompiler





#the following two lines are very important to include some missing libraries

QMAKE_LFLAGS += -Wl,-rpath-link,$$[QT_SYSROOT]/lib/arm-linux-gnueabihf

QMAKE_LFLAGS += -Wl,-rpath-link,$$[QT_SYSROOT]/usr/lib/arm-linux-gnueabihf

QMAKE_CFLAGS   += -mcpu=cortex-a15 -mfpu=neon-vfpv4 -marm


DISTRO_OPTS    += hard-float

# Preferred eglfs backend



10. Configure qmake:
Note: ubuntu 18 of Odroid-XU4 comes with ssl1.1.0, so Qt versions below 5.10 will not compile due to ssl linking errors

Code: Select all

mkdir ~/Odroid/qt5-build
cd ~/Odroid/qt5-build
Configuration of qmake:

Code: Select all

/home/username/Qt5.10.0/5.10.0/Src/configure -opensource -confirm-license -opengl es2 -xcb -eglfs -qpa xcb \
-prefix /usr/local/qt5xu -release -make libs -no-use-gold-linker \
-device linux-odroid-xu3-g++ -device-option \
CROSS_COMPILE=/home/ggg/Odroid/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- \
-sysroot /mnt/odroid.img -nomake tests -nomake examples -no-pch \
-hostprefix ~/Odroid/qt5xu -skip qtwayland \
-no-webengine-pepper-plugins -no-webengine-geolocation -no-webengine-spellchecker \
-no-webengine-webrtc -no-webengine-pulseaudio 
-prefix : location of qt5 on target device
-hostprefix: location of qmake, moc and other stuff on host machine (to be used later for QtCreator setup to define Qt version)
qtwayland has conflict issue with xcb (x11) header files, so we skip it. In fact we do not need it.

11. After successful confiuration with no errors, check the log of the configuration and ensure that there is no error.

Note: compiler will try to link with existing libQt5* in folder /mnt/odroid/user/lib/arm-linux-gnueabihf so either move all libQt5* files from this folder
or use the following command on XU4 before image preparation: sudo apt-get remove libqt5*

Compile and make Qt:

Code: Select all

sudo make  -j5
Note: You can remove -jN to disable multitasking during build and see full errors and make details, but will take much longer time
Note: compile time is long especially for webengine (3 to 6 hours, depend on you system).Leave your ubuntu free during make

Note:Qt will be installed into '/mnt/odroid.img//usr/local/qt5xu'.

After successful compile with no errors:

Code: Select all

sudo make install

12. umount the image and write it back to SD/eMMC

Code: Select all

sudo umount /mnt/odroid.img
copy it back to an SD, use Etcher for Linux.

Alternatively, (with root privilege) you can copy the driectory containing qt5: /mnt/odroid.img//usr/local/qt5xu
to your SD/eMMC card and place it inside: /usr/local/

13. To develop on Qt Creator,
reMount the image:

Code: Select all

sudo mount ./xu4.img -o loop,offset=$((512*264192)) /mnt/odroid.img/
Run Qt Creator, add device in Qt creater (use latest Qt Creator 4.5 based on Qt 5.10 to overcome some General messages errors)
Note: if some General Messages errors appear during project creation or opening, neglect them and Built Project, they will disappear.

1.) Add Generic linux device
2.1) Add compiler: GCC: /home/username/Odroid/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++
2.2) Add debugger: /home/username/Odroid/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gdb
3.) Add Qt version: /home/username/Odroid/qt5xu/bin/qmake (same as -hostprefix or you can refer to qt5xu on /mnt/odroid.img/usr/local)
4.) Add kit and set its sysroot to: /mnt/odroid.img

Important: Also add the following Run Environmental Variables to your projects
XAUTHORITY =/home/odroid/.Xauthority

Note: Do not forget to add the following lines to your .pro file:

target.path += /home/odroid
INSTALLS += target

Happy Qt-ing
These users thanked the author jaf_kh for the post:
odroid (Mon Aug 05, 2019 3:07 pm)

User avatar
Site Admin
Posts: 35852
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
Has thanked: 1305 times
Been thanked: 908 times

Re: QT 5.10 cross compile for Odroid-XU4

Post by odroid »

Thank you for the very detail instruction. :)

Posts: 16
Joined: Thu Jul 25, 2019 4:09 pm
languages_spoken: english
ODROIDs: Odroid-XU4
Has thanked: 0
Been thanked: 8 times

Re: QT 5.10 cross compile for Odroid-XU4

Post by jaf_kh »

You welcome.
Yes, it took me three days reading relevant subjects and forums, especially texas instruments wiki. ;)

Post Reply

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 1 guest