编译主机: Ubuntu20.04
Qt源码版本: qt-everywhere-opensource-src-5.15.2.tar.gz
交叉编译工具: arm-linux-gnueabihf-gcc
1、下载解压,然后cd
到文件夹下
tar -vzxf qt-everywhere-opensource-src-5.15.2.tar.gz cd qt-everywhere-opensource-src-5.15.2
2.修改交叉编译架构用到的信息
(1).cd
到如下目录,ls
可以看到qt支持的交叉编译器列表
cd qt-everywhere-opensource-src-5.15.2/qtbase/mkspecs/ ls
(2).一定要找到自己实际使用的编译器,这里是arm-linux-gnueabihf-gcc
,发现没有这个目录,没关系,我们创建一个
mkdir arm-linux-gnueabihf-gcc
(3).然后复制其他平级文件夹中的两个文件qmake.conf
和qplatformdefs.h
到这个目录下
(4).打开qmake.conf
,修改一下你的交叉编译器的绝对路径,和需要预编译的模块路径,如tslib
TF显示屏模块和sqlite
数据库模块,这里单独去编译,不在此赘述
# # qmake configuration for building with arm-linux-gnueabihf-g++ # MAKEFILE_GENERATOR = UNIX CONFIG += incremental QMAKE_INCREMENTAL_STYLE = sublib QT_QPA_DEFAULT_PLATFORM = linux #eglfs QMAKE_CFLAGS_RELEASE += -O2 -march=armv7-a QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv7-a include(../common/linux.conf) include(../common/gcc-base-unix.conf) include(../common/g++-unix.conf) QMAKE_INCDIR += /opt/tslib/include /opt/sqlite3/include #指定头文件,需预编译 QMAKE_LIBDIR += /opt/tslib/lib /opt/sqlite3/lib #指定库文件,需预编译 # modifications to g++.conf QMAKE_CC = /usr/local/arm/arm-gcc/bin/arm-linux-gnueabihf-gcc -lts QMAKE_CXX = /usr/local/arm/arm-gcc/bin/arm-linux-gnueabihf-g++ -lts QMAKE_LINK = /usr/local/arm/arm-gcc/bin/arm-linux-gnueabihf-g++ -lts QMAKE_LINK_SHLIB = /usr/local/arm/arm-gcc/bin/arm-linux-gnueabihf-g++ -lts # modifications to linux.conf QMAKE_AR = /usr/local/arm/arm-gcc/bin/arm-linux-gnueabihf-ar cqs QMAKE_OBJCOPY = /usr/local/arm/arm-gcc/bin/arm-linux-gnueabihf-objcopy QMAKE_NM = /usr/local/arm/arm-gcc/bin/arm-linux-gnueabihf-nm -P QMAKE_STRIP = /usr/local/arm/arm-gcc/bin/arm-linux-gnueabihf-strip load(qt_config)
3.编写生成Makefile的脚本
(1).cd到qt源码根目录
(2).新建一个autoConfigure.sh
脚本
#!/bin/sh ./configure \ -v \ -prefix /opt/qt-5.15.2 \ -release \ -opensource \ -no-accessibility \ -make libs \ -xplatform arm-linux-gnueabihf-g++ \ -optimized-qmake \ -pch \ -qt-sql-sqlite \ -qt-zlib \ -skip qtdeclarative \ -no-opengl \ -no-sse2 \ -no-openssl \ -no-cups \ -no-glib \ -no-pkg-config \ -no-separate-debug-info \ -tslib \ -I/opt/tslib/include \ -L/opt/tslib/lib
-xplatform arm-linux-gnueabihf-g++ \
#这个名字要与2.(2)中创建的目录名字一致,否则检索不到,一般与编译器同名,但未必,需注意
c-qt-sql-sqlite \
需预编译,如果没有提前编译,执行脚本会报如下错误,下面的-tslib \
同理
ERROR: Invalid value given for boolean command line option 'sql-sqlite'.
(3).运行脚本
./autoConfigure.h
完成,qt源码根目录已生成Makefile
3.编译
(1).在源码根目录make
make
(2).生成可移植的库到/opt/qt.5.15.2
make install
在/opt/qt-5.15.2
下可看到如下文件夹,说明编译成功