参考正点原子:08【正点原子】I.MX6U移植Qt5.12.9_V1.1.pdf 手册
1.下载Qt5.12.9源码
在此链接中下载Qt5.12.9的源码:https://download.qt.io/archive/qt/5.12/5.12.9/single/https://download.qt.io/archive/qt/5.12/5.12.9/single/也可以自行下载其他版本的源码。将下载好的源码拷贝至Ubunttu,然后进行解压:
tar xf qt-everywhere-src-5.12.9.tar.xz
cd qt-everywhere-src-5.12.9/
2.修改 qmake.conf
编辑以下路径中的qmake.conf文件:
vi qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf
完整配置文件如下,可直接复制,主要修改了其编译器指向:
#
# qmake configuration for building with arm-linux-gnueabi-g++
#
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
QT_QPA_DEFAULT_PLATFORM = linuxfb
QMAKE_CFLAGS += -O2 -march=armv7-a -mtune=cortex-a7 -mfpu=neon -mfloat-abi=hard
QMAKE_CXXFLAGS += -O2 -march=armv7-a -mtune=cortex-a7 -mfpu=neon -mfloat-abi=hard
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC = arm-linux-gnueabihf-gcc
QMAKE_CXX = arm-linux-gnueabihf-g++
QMAKE_LINK = arm-linux-gnueabihf-g++
QMAKE_LINK_SHLIB = arm-linux-gnueabihf-g++
# modifications to linux.conf
QMAKE_AR = arm-linux-gnueabihf-ar cqs
QMAKE_OBJCOPY = arm-linux-gnueabihf-objcopy
QMAKE_NM = arm-linux-gnueabihf-nm -P
QMAKE_STRIP = arm-linux-gnueabihf-strip
load(qt_config)
3.配置编译选项
构建一个脚本,使用正点原子提供的脚本来进行编译:
vi autoconfigure.sh
主要修改内容如下:( 1 ) /home/alientek/ qt-everywhere-src-5.12.9/arm-qt 为编译输出路径。( 2 ) /home/alientek/tslib-1.21/arm-tslib/include 为第二章 tslib 头文件路径。( 3 ) /home/alientek/tslib-1.21/arm-tslib/lib 为第二章 tslib 相关库文件路径。
./configure -prefix /home/lpy/linux/qt/qt-everywhere-src-5.12.9/arm-qt \
-opensource \
-confirm-license \
-release \
-strip \
-shared \
-xplatform linux-arm-gnueabi-g++ \
-optimized-qmake \
-c++std c++11 \
--rpath=no \
-pch \
-skip qt3d \
-skip qtactiveqt \
-skip qtandroidextras \
-skip qtcanvas3d \
-skip qtconnectivity \
-skip qtdatavis3d \
-skip qtdoc \
-skip qtgamepad \
-skip qtlocation \
-skip qtmacextras \
-skip qtnetworkauth \
-skip qtpurchasing \
-skip qtremoteobjects \
-skip qtscript \
-skip qtscxml \
-skip qtsensors \
-skip qtspeech \
-skip qtsvg \
-skip qttools \
-skip qttranslations \
-skip qtwayland \
-skip qtwebengine \
-skip qtwebview \
-skip qtwinextras \
-skip qtx11extras \
-skip qtxmlpatterns \
-make libs \
-make examples \
-nomake tools -nomake tests \
-gui \
-widgets \
-dbus-runtime \
--glib=no \
--iconv=no \
--pcre=qt \
--zlib=qt \
-no-openssl \
--freetype=qt \
--harfbuzz=qt \
-no-opengl \
-linuxfb \
--xcb=no \
-tslib \
--libpng=qt \
--libjpeg=qt \
--sqlite=qt \
-plugin-sql-sqlite \
-I/home/lpy/linux/tool/tslib-1.21/arm-tslib/include \
-L/home/lpy/linux/tool/tslib-1.21/arm-tslib/lib \
-recheck-all
给予脚本执行权限:
chmod +x autoconfigure.sh
然后安装g++编译器:
sudo apt-get install g++
直接执行脚本:
./autoconfigure.sh
由于博主使用的是Ubuntu22.04版本,g++版本为11,编译会报错C++11错误,是因为我们的g++版本过高,qt源码版本过低,有两种解决方案:(1)降低g++版本。(2)使用更新版本的qt源码。这里我们选择降低g++版本:
(1)在Ubuntu22.04中是无法找到这么低的g++版本的,需要添加镜像源
sudo vim /etc/apt/sources.list
在文件末尾添加镜像源:
deb [arch=amd64] http://archive.ubuntu.com/ubuntu focal main universe
更新镜像源:
sudo apt-get update
(2)安装g++-7
sudo apt install -y g++-7
为g++-7创建软连接
sudo ln -s /usr/bin/g++-7 /usr/bin/g++
查看g++版本,此时发现已经成功安装7.5.0版本的g++:
g++ --version
此时再次编译脚本:
./autoconfigure.sh
如图所示代表配置成功!
4.开始编译 Qt5.12.9 源码
直接执行make编译:
time (make -j 16) // -j 16 代表最多允许 16 条编译指令同时运行,参数 16,一般为
个人分配给虚拟机的核心数的 2 倍,前面加个 time 是测试编译时间。
编译完成!
执行安装指令后,查看安装后的内容。
make install
ls arm-qt
安装成功!