Porting QT to arm environment under linux

foreword

Let’s talk about the entire project process. Our goal is to put the program compiled by qt on the arm development board and run it. First, download the QT source code and tslib source code (QT source code compilation and QT program operation require the support of the tslib library), and use it in the virtual machine Cross-compilation Compile and install the QT source code, generate arm environment library files and qmake, then install the Linux version of qt in the virtual machine, configure the qt compilation environment after installation, change the compiler to a cross compiler, and add the arm environment The qmake can. Next, build a qt project casually, compile the program with the arm compilation environment, and put the program into the arm development board. At this time, it cannot run yet. You need to put the previously compiled qt and tslib library files on the development board, and finally set Good environment variables, after finishing the touch calibration, you can run the qt program.

Source code download

QT source code and QT software download

Index of /archive/qt

Select the appropriate version and click to enter. The single file is the QT source code. The version I use here is QT5.9.6

If you are not sure how to install QT in a virtual machine, you can refer to this article of mine

Super detailed installation of QT in linux environment - linux qt_yuansec's blog - CSDN blog

tslib source code download

 https://gitlab.com/tslib/tslib/-/archive/1.4/tslib-1.4.tar.gz 

The version 1.4 is used here

If you don't want to compile the source code, I put the compiled tslib source code and qt source code library files in my gitee, which can be downloaded and used directly

qt porting arm: qt builds a cross-compilation environment under linux, and runs the program in the arm environment (gitee.com)

Cross compiler download

The cross compiler I use is arm-none-linux-gnueabi-gcc, and I use the 2014.05-29 decompressed version of linux

[ARM-Linux development] download and install arm-none-Linux-gnueabi-gcc - ZhangPYi - Blog Garden (cnblogs.com)

If you don’t know how to install it, you can refer to this article of mine

Ubuntu installs the cross compiler arm-linux-gcc_yuansec's blog-CSDN blog_arm gcc4.6.4

source code compilation

I won't talk about the compilation of tslib here. This is relatively simple. You can directly use my compiled ones without any impact (but you must ensure that the cross-compiler is consistent. I use arm-none-linux-gnueabi- gcc)

Let's focus on the compilation of the qt source code, create a folder /opt in the root directory, copy the downloaded qt source code package to this directory and decompress it, why can't it be placed directly on the desktop, because the directory where the qt source code is located cannot contain Chinese, Of course, if your desktop does not contain Chinese, you can compile it on the desktop

Then enter the decompressed source code directory and find the linux-arm-gnueabi-g++ folder under the qtbase/mkspecs/ directory

Make a copy of it and name it arm-none-linux-gnueabi-g++ (the cross compiler you are using)

sudo cp -r linux-arm-gnueabi-g++ arm-none-linux-gnueabi-g++

Enter the copied folder, find the qmake.conf folder, open it with Notepad, and check whether the compiler used in it has become the same as the cross compiler you use

 After you're done, you can cut it

Before this, create a folder qt5 in the /opt directory (the file directory of the library generated after compilation)

Then put the tslib library file in the /opt directory

Then build a script auto.sh in the root directory of the source code and add the following code

#!/bin/sh
./configure \
-v \
-prefix /opt/qt5 \  //生成路径
-release \
-opensource \
-no-accessibility \
-make libs \
-xplatform arm-none-linux-gnueabi-g++ \  //你的编译器
-optimized-qmake \
-pch \
-qt-zlib \
-tslib \
-no-opengl \
-no-sse2 \
-no-openssl \
-no-cups \
-no-glib \
-no-pkg-config \
-no-separate-debug-info \
-I/opt/tslib1.4/include -L/opt/tslib1.4/lib  //tslib的库

Next, execute the script directly to crop

./auto.sh

 The next step is to compile and install

make -j4
sudo make install

After completion, the required files will be generated in the previously built qt5 folder

Among them, there is the qmake file we need in the bin directory

 Package the lib and plugins folders directly and take them out for later use. They must be packaged, because the library files under lib have link attributes. If they are copied directly, their link attributes will be lost.

At this time, open the qt software, and then open the tool - option - build and run

First set up the compiler and add a C++ compiler, as shown in the figure below

Then manually add a version, qmake is just compiled.

 Finally, add the compiler and version we set under the build suite

After the completion, the arm compilation environment of qt is set up, and then one or two components are randomly placed, and after compilation, they are taken out and ready to be put on the arm development board to run.

Arm environment construction

Create a directory in your arm development board, /usr/local, and then create two folders qt and tslib, put the previously compressed lib and plugins files in the qt directory to decompress, and tslib is the same

 Then open the /etc/profile file of the arm development board and add the following content

export PATH PS1 OPIEDIR QPEDIR QTDIR EDITOR TERM
export TS_ROOT=/usr/local/tslib    //放入的tslib目录
export LD_LIBRARY_PATH=$TS_ROOT/lib:$LD_LIBRARY_PATH
export PATH=$TS_ROOT/bin:$PATH
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CALIBFILE=$TS_ROOT/etc/pointercal
export TSLIB_CONFFILE=$TS_ROOT/etc/ts.conf
export TSLIB_PLUGINDIR=$TS_ROOT/lib/ts
# qt
export QT_ROOT=/usr/local/qt    //放入的qt目录
export LD_LIBRARY_PATH=$QT_ROOT/lib/:$LD_LIBRARY_PATH
export QT_PLUGIN_PATH=$QT_ROOT/plugins
export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0
export QT_QPA_FONTDIR=$QT_ROOT/lib/fonts
export QT_QPA_GENERIC_PLUGINS=tslib
export QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=/dev/input/event0:inverty
export QT_QPA_FB_TSLIB=1
export LD_PRELOAD=$TS_ROOT/lib/libts.so

 After adding and setting environment variables

source /etc/profile

 At this time, the program can't run yet. For the first time, you need to do touch calibration settings, and execute the ts_calibrate program in the tslib/bi directory.

./usr/local/tslib/bin/ts_calibrate

After the touch calibration is completed, you can put the qt program you compiled into the arm development board to execute (be careful not to forget to grant permissions, otherwise the program cannot be executed without permissions).

Guess you like

Origin blog.csdn.net/lhh2333/article/details/128836570