Skip to content

How to Cross Compile Qt Library

Félix Roy edited this page Nov 30, 2019 · 17 revisions

Introduction

This wiki page explains how to configure the host computer so it can compile the Steno application that will later run on the target. In other words, here's how to setup the cross-compiling environnement on the host computer.

Prerequisits

The target must have the NVIDIA Jetpack SDK installed. See wiki page.

The target must be configured. See wiki page.

To make the building environnement easier to use and understand, it's suggested to create a working directory in the home folder of host computer.

mkdir $HOME/path_to_working_directory

NOTE - For the rest of the procedure, it will be assume that the working directory is $HOME/tx2

Install the prerequisite packages

sudo apt-get install -y 'libxcb.*' \
libx11-xcb-dev libglu1-mesa-dev \
libxrender-dev libxi-dev libinput* \
mtdev* mesa-utils \
mesa-utils-extra libgles2-mesa-dev

Procedure

Target Root File System

Some parts of the target rootfs are required on the host computer.

  1. Make a directory that will act as the target rootfs

    mkdir $HOME/tx2/rootfs
    
  2. Copy required folders from target to host computer rootfs folder.

    rsync -avz -e ssh nvidia@target_ip:/lib/aarch64-linux-gnu --relative $HOME/tx2/rootfs
    rsync -avz -e ssh nvidia@target_ip:/usr/include --relative $HOME/tx2/rootfs
    rsync -avz -e ssh nvidia@target_ip:/usr/lib --relative $HOME/tx2/rootfs
    rsync -avz -e ssh nvidia@target_ip:/usr/local/cuda-10.0/include/ --relative $HOME/tx2/rootfs
    rsync -avz -e ssh nvidia@target_ip:/usr/local/cuda-10.0/lib64/ --relative $HOME/tx2/rootfs
    
  3. Fix symbolic links rootfs by executing this script on the rootfs folder.

    git clone https://github.com/alpqr/fixsymlinks_tx1 $HOME/tx2/fixsymlinks
    chmod +x $HOME/tx2/fixsymlinks/fixsymlinks.sh
    $HOME/tx2/fixsymlinks/fixsymlinks.sh $HOME/tx2/rootfs
    

Toolchain

The linaro toolchain version 7.4.1 will be used fro compilation purpose.

  1. Download linaro toolchain

    wget -P /tmp "https://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz"
    
  2. Unpack the archive

    tar -xvf /tmp/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz -C $HOME/tx2/
    

Qt

The Qt 5.12.6 library needs to be compiled for the target architecture.

  1. Download qt-everywhere

    wget -P /tmp "https://download.qt.io/archive/qt/5.12/5.12.6/single/qt-everywhere-src-5.12.6.tar.xz" 
    
  2. Unpack the archive

    tar -xvf /tmp/qt-everywhere-src-5.12.6.tar.xz -C /tmp
    
  3. Comment out the line 29, in file /tmp/qt-everywhere-src-5.12.6/qtbase/mkspecs/devices/linux-jetson-tx1-g++/qmake.conf

    sed -i '29 s/^/#/' /tmp/qt-everywhere-src-5.12.6/qtbase/mkspecs/devices/linux-jetson-tx1-g++/qmake.conf
    
  QMAKE_INCDIR_POST += \
  #    $$[QT_SYSROOT]/usr/include \
  $$[QT_SYSROOT]/usr/include/aarch64-linux-gnu
 
  QMAKE_LIBDIR_POST += \
  1. Go to qt-everywhere folder

    cd  /tmp/qt-everywhere-src-5.12.6
    
  2. Configure the build

    ./configure -shared -c++std c++14 -v \
    -opensource -release --confirm-license \
    -device linux-jetson-tx1-g++ \
    -device-option CROSS_COMPILE=$HOME/tx2/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- \
    -sysroot $HOME/tx2/rootfs \
    -nomake examples -nomake tests \
    -prefix /usr/local/qt5 \
    -extprefix $HOME/tx2/qt5 \
    -hostprefix $HOME/tx2/qt5 \
    -skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcanvas3d -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtlocation -skip qtmacextras -skip qtnetworkauth -skip qtpurchasing -skip qtquickcontrols -skip qtquickcontrols2 -skip qtremoteobjects -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qttools -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns -skip qtwebengine
    
  3. Build and install

    make -j$(nproc)
    make install
    

Qt Library on the Target

Look in the folder /usr/local/qt5/ on the target. If it's EMPTY proceed with the following command else skip this step. The command will install the compiled Qt library on the target.

scp -r $HOME/tx2/qt5 nvidia@target_ip:/usr/local

What's next?

The next step is to Cross-Compile the Steno Application with QtCreator.

References