Qt is one of the best toolkits for designing graphical user interfaces available. It is designed to be easy to use for all levels of experience, and a great place to start learning app development and 3d graphical design. Many people want to cross compile Qt to embedded devices such as the Raspberry Pi or Nvidia Jetson series. In this tutorial I will be showing you how.
Cross Compile Setup
Cross Compiling Qt for each board is slightly different, but this guide should work for most common boards. First we need to create a folder where we install everything. Place this in the home directory and name it qt5jnano or something easy to remember.
Installing the Toolchain
The first step in cross compiling is to find the cross compile toolchain for your board. For the Nvidia Jetson, you can find this on Nvidia Developer downloads page. Look for “GCC Tool Chain for 64-bit BSP” (or 32-bit if that’s what you need), and download the latest version. For Raspberry Pi’s you should easily be able to find a toolchain online such as this one or many others. Keep in mind that if you are using a Raspberry Pi, the directories I mention might not be exactly the same, and you will need to change what you do slightly. Extract the file into the qt5jnano directory
Creating a Sysroot
The sysroot is where we are going to be storing all of the libraries from your embedded system. If you haven’t already, turn your board on and connect it to your laptop headlessly. For the Jetson boards it is as simple as connecting the micro usb port from the board to a usb port on the laptop. On the Raspberry Pi it requires some more setup however. Once you are ready, create a sysroot folder in qt5jnano along with a usr and lib folder inside the sysroot. Finally, run the following commands:
cd qt5jnano
rsync -avz jnano@192.168.55.1:/lib sysroot
rsync -avz jnano@192.168.55.1:/usr/include sysroot/usr
rsync -avz jnano@192.168.55.1:/usr/lib sysroot/usr
This will upload all of the libraries from your embedded device onto your host machine so you can use them. The final step is to adjust the symbolic links in the sysroot to be relative with these commands:
wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot
Install Qt
The next obvious step is to install the Qt version you would like to use. In this guide I am using Qt 5.15.1, but feel free to use whatever version you want (at your own risk). Keep in mind that I have tested this with Qt 5.12.5 and Qt 6.0.0 and it does not work. Go to the Qt download page and choose your version, then open the “single” directory and download the tar.xz archive. Then extract it into the qt5jnano folder.
Add Jetson Nano Device
Qt 5 and 6 come installed with specific devices which you can configure it to cross compile to in the installation. The only problem is that the Jetson Nano isn’t included here. If you are using any of the other Jetson boards, or a Raspberry Pi, feel free to skip this step, since all of those are included. If not, please download this device that I created for the Jeston Nano. Extract the folder and place it in the “qt5jnano/qt-everywhere-src-5.15.1/qtbase/mkspecs/devices” directory (the qt-everywhere-src-5.15.1 might have a different name for different versions of Qt).
Configure Qt to Cross Compile
Before doing this step, make sure you have at least 15 GB space on your computer. The first time I did this, I had too little space, and the installation got completely messed up so I had to restart. First, make a qt5build directory in the qt5jnano folder. Now open up the terminal and type these commands:
cd qt5jnano/qt5build
../qt-everywhere-src-5.15.1/configure -opengl es2 -device linux-jetson-nano -device-option CROSS_COMPILE=/home/$USER/qt5jnano/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- -sysroot /home/$USER/qt5jnano/sysroot -prefix /usr/local/qt5jnano -opensource -confirm-license -skip qtscript -skip wayland -skip qtwebengine -force-debug-info -skip qtlocation -nomake examples -make libs -pkg-config -no-use-gold-linker -v
make -j4
make install
Congratulations! Qt has now been successfully be configured for cross compilation. The final step is to add the kit to Qt Creator.
Set Up Qt Creator
Compiler
First we need to add a compiler. To do this open Qt Creator and navigate to the Kits section in options and select compilers. After this hit add, GCC, and then add the C and C++ compilers from the toolchain.
Qt Versions
Next we need to add the Qt Versions, so move to the Qt Versions tab, hit add, and then navigate to the qt5jnano folder, then open the sysroot, go to usr, local, qt5jnano, bin, and finally select qmake. After this, Qt Creator should automatically recognize the Qt installation and register it as “Qt 5.15.1 (qt5jnano).”
Devices
The last thing we need to configure before we create a kit is the device. In the options tab, navigate to devices, and add a “Generic Linux Device”. Once you do this, it will start a setup wizard. Enter the name, ip address, and username of that device. After this, it will ask if you want to set up public key authentication. If you would like to, power on your embedded device, connect it to your PC, then hit “create new key pair”, and then “deploy public key.” Now finish the setup and you are ready to create a kit!
Kits
The final step is to create a kit with everything. To do this open the kits tab, select add, and then fill the following boxes.
- Name it whatever you want
- Set the device type to Generic Linux Device
- Device is the one you created
- C and C++ compilers are the ones you created
- Set Debugger to none
- Qt Version is the one you created.
Conclusion
If you did everything right, you should now have a working cross compile setup from your linux PC to an embedded device. With this setup you should also be able to use libraries specific to your device, such as WiringPi. The Jetson Nano even comes preinstalled with OpenCV, and after a little bit of tweaking, I was able to use this with my setup as well. If you have any questions, comments, or concerns, please comment down below. If not, I’ll see you next time.
Leave a Reply