QT embedded Linux arm porting

Posted by designxperts on Tue, 01 Feb 2022 20:59:03 +0100

1, Environmental preparation

Compilation environment: Ubuntu 20 . 04 (Download address: https://ubuntu.com/download/desktop)
QT Source code( QT5.9.5 Download address: https://download.qt.io/archive/qt/5.9/5.9.5/)
Cross compiler( arm-2014.05)

2, Compilation preparation

1.decompression qt Source code
2.Configure the path of the cross compiler  
$ vim /etc/profile

#Add the last line of the file

export PATH=/opt/arm-2014.05/bin:$PATH

Make effective

source profile

Determine whether it is effective:

arm-none-linux-gnueabi-gcc -v   #If the version number of the cross compiler can be displayed, it will be successful

3, QT source code cross compilation

1. Specify the architecture of the target platform and the type of cross compiler

(QT5 has corresponding configuration files, so you only need to modify qmake.conf)

vi qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf     #Under the source code path

Here is the modified qmake Conf, the contents of which need to be modified according to their actual situation.

#
# qmake configuration for building with arm-linux-gnueabi-g++
#


MAKEFILE_GENERATOR      = UNIX
CONFIG                 += incremental
QMAKE_INCREMENTAL_STYLE = sublib


#define the architecture of arm
QT_QPA_PLATFORM = linuxfb:fb=/dev/fb0
QMAKE_CFLAGS_RELEASE += -O2 -march=armv7-a
QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv7-a
#end


include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)


# modifications to g++.conf
QMAKE_CC                = /opt/arm-2014.05/bin/arm-none-linux-gnueabi-gcc
QMAKE_CXX               = /opt/arm-2014.05/bin/arm-none-linux-gnueabi-g++
QMAKE_LINK              = /opt/arm-2014.05/bin/arm-none-linux-gnueabi-g++
QMAKE_LINK_SHLIB        = /opt/arm-2014.05/bin/arm-none-linux-gnueabi-g++


# modifications to linux.conf
QMAKE_AR                = /opt/arm-2014.05/bin/arm-none-linux-gnueabi-ar cqs
QMAKE_OBJCOPY           = /opt/arm-2014.05/bin/arm-none-linux-gnueabi-objcopy
QMAKE_NM                = /opt/arm-2014.05/bin/arm-none-linux-gnueabi-nm -P
QMAKE_STRIP             = /opt/arm-2014.05/bin/arm-none-linux-gnueabi-strip

load(qt_config)

Two changes have been made here. One is to define the architecture of arm, including QT_QPA_PLATFORM is a plug-in that specifies the QPA platform. linuxfb is selected here,
Parameter - O is the optimization options provided by the compiler, such as - O, - O1, - O2, - O3, etc., representing different optimization levels,
The architecture of the target processor is specified after the - march parameter (different architectures may be specified and different instruction sets will be called, guess ~)
Another change is to change the following G + + Conf and Linux The complete path is added to the parameter value in conf, such as arm none Linux gnueabi GCC. This is the cross compiler I choose, which can be modified according to my own situation.

2. Configure Qt according to requirements

Qt can be configured through the configure script in the source package. After running the configure script, you will get the makefile file, and then compile and install through the make and make install commands. A script is written here to implement the configuration steps.

vim icedustpan.sh   #Create compilation script

Script description:
-prefix /opt/newQt5.9.5_arm/newQt5.9.5_arm_install \ is the detailed description of the installation path( https://www.bilibili.com/video/BV1tp4y1i7EJ?p=17 )p17 is introduced

./configure \
    -v\
    -prefix /opt/newQt5.9.5_arm/newQt5.9.5_arm_install \
    -release \
    -make libs\
    -xplatform linux-arm-gnueabi-g++ \
    -optimized-qmake \
    -pch \
    -qt-zlib \
    -no-opengl \
    -no-sse2 \
    -no-openssl \
    -no-cups \
    -no-separate-debug-info \
    -nomake examples -nomake tools

Grant authority:

chmod +x icedustpan.sh

Execute configuration QT script

./icedustpan.sh

3. Compile Qt

make -j4
sudo make install

4. Migrate to ARM

Copy the lib and plugins of QT compiled and installed by yourself to the development version
Configure the environment variables of arm

vi etc/profile
export LD_LIBRARY_PATH=/usr/local/qt5.9.6/lib
export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/local/qt5.9.6/plugins
export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0
export QT_QPA_FONTDIR=/usr/local/qt5.9.6/lib/fonts

5. Install Qt Creator

Download path: https://download.qt.io/archive/qt/

6. Configure Qt Creator

Configuration steps
Click Tools - > Options:

Click build run, and then click compiler:

Click Add - > GCC - > C:

Compiler path filling:
/opt/arm-2014.05/bin/arm-none-linux-gnueabi-gcc
Then click Apply:

The same is true for C + +
Click Add - > GCC - > C + +:

Compiler path filling:
/opt/arm-2014.05/bin/arm-none-linux-gnueabi-g++
Then click Apply:

Click Qt Versions, and then click Add:
Select qmake as shown in the following figure, and then click Apply:

Click Debuggers, and then click Add:

Name: Qt5 9.5-imx6
Path fill in:
/home/ubuntu1404/work/arm-2014.05/bin/arm-none-linux-gnueabi-gdb
Then click Apply

Click on Kits, and then click Add:

Name: Qt5 9.5-imx6
Sysroot fill in: / home / Ubuntu 1404 / work / arm-2014.05/bin
Compiler C select GCC
Compiler C + + select GCC
Debuggers select Qt5 9.5-imx6
Qt version select Qt 5.9.5(qt5)
Finally, click OK.

After configuration, close Qt creator.

7. Start Qt Creator

Use the root user to run on the terminal: < installation directory > / bin / qtcreator sh
Clicking the icon directly may not compile, suggesting that some libraries cannot be found

8. Relevant environment

Topics: Linux Qt Embedded system ARM