在嵌入式系统开发领域,针对特定硬件平台进行Qt框架的移植与适配是一项关键技术任务。作为业界主流的跨平台应用开发框架,Qt凭借其完善的图形界面支持能力,在嵌入式开发图形界面应用程序中占据重要地位。本文将基于ELF 1开发板详细阐述Qt 5.12 版本的交叉编译与系统移植方案。
elf@ubuntu:~/work$ unzip qtsrc512-master.zip
elf@ubuntu:~/work$ chmod 777 -R qtsrc512-master(设置最大权限,避免编译时权限问题)
elf@ubuntu:~/work$ cd qtsrc512-master/
(2)修改qmake.conf配置文件
elf@ubuntu:~/work/qtsrc512-master$ 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
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC                = arm-poky-linux-gnueabi-gcc  -march=armv7ve -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi
QMAKE_CXX               = arm-poky-linux-gnueabi-g++  -march=armv7ve -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi
QMAKE_LINK              = arm-poky-linux-gnueabi-g++  -march=armv7ve -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi
QMAKE_LINK_SHLIB        = arm-poky-linux-gnueabi-g++  -march=armv7ve -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi
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
QMAKE_LDFLAGS           = -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed  -Wl,-z,relro,-z,now
# modifications to linux.conf
QMAKE_AR                = arm-poky-linux-gnueabi-ar cqs
QMAKE_OBJCOPY           = arm-poky-linux-gnueabi-objcopy
QMAKE_NM                = arm-poky-linux-gnueabi-nm -P
load(qt_config)
elf@ubuntu:~/work/qtsrc512-master$ touch shell.sh
elf@ubuntu:~/work/qtsrc512-master$ chmod 777 shell.sh
./configure -prefix /home/elf/work/qtsrc512-master/__install 
-opensource 
-confirm-license 
-release 
-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 qtxmlpatterns 
-make libs 
-make examples 
-nomake tools -nomake tests 
-gui 
-widgets 
-dbus-runtime 
--glib=no 
--iconv=no 
--pcre=qt 
--zlib=qt 
-no-openssl 
--xcb=qt 
--freetype=qt 
--harfbuzz=qt 
-no-opengl 
--libpng=qt 
--libjpeg=qt 
--sqlite=qt 
-plugin-sql-sqlite 
-recheck-all 
-no-strip
(2)执行环境变量
elf@ubuntu:~/work/qtsrc512-master$ . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
(3)编译
运行脚本并进行编译。
elf@ubuntu:~/work/qtsrc512-master$ ./shell.sh
+ cd qtbase
+ /home/elf/work/qtsrc512-master/qtbase/configure -top-level -prefix /home/elf/work/qtsrc512-master/__install -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 qtxmlpatterns -make libs -make examples -nomake tools -nomake tests -gui -widgets -dbus-runtime --glib=no --iconv=no --pcre=qt --zlib=qt -no-openssl --xcb=qt --freetype=qt --harfbuzz=qt -no-opengl --libpng=qt --libjpeg=qt --sqlite=qt -plugin-sql-sqlite -recheck-all
Please make sure to unset the QMAKESPEC, XQMAKESPEC, QMAKEPATH,
and QMAKEFEATURES environment variables prior to building Qt.
elf@ubuntu:~/work/qtsrc512-master$ unset QMAKESPEC XQMAKESPEC QMAKEPATH QMAKEFEATURES
elf@ubuntu:~/work/qtsrc512-master$ ./shell.sh
elf@ubuntu:~/work/qtsrc512-master$ make
elf@ubuntu:~/work/qtsrc512-master$ make install
编译完成后,__install 文件夹包含了 Qt 5.12 所需的所有文件。
elf@ubuntu:~/work/qtsrc512-master$ cd __install/
elf@ubuntu:~/work/qtsrc512-master/__install$ ls
bin  doc  examples  include  lib  mkspecs  plugins  qml
其中,lib文件夹为所需的lib库,examples文件夹为demo工程。
elf@ubuntu:~/work/qtsrc512-master/__install$ tar -cjvf qt5.12.tar.bz2 *
(2)解压至开发板
将打包后的文件放到U盘,拷贝至开发板并解压。
root@ELF1:~# tar -mxvf qt5.12.tar.bz2 -C /
(3)执行环境变量
在开发板上设置环境变量,确保 Qt 正常运行。其中export QT_ROOT=/ 为qt5.12文件相关的路径(填解压的路径)。
export QT_ROOT=/
export QT_QPA_FONTDIR=/usr/share/fonts
export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins
export QT_PLUGIN_PATH=$QT_ROOT/plugins
export LD_LIBRARY_PATH=$QT_ROOT/lib:$QT_ROOT/plugins/platforms
export QML2_IMPORT_PATH=$QT_ROOT/qml
//两种显示框架根据需求进行设置
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0     //采用Linuxfb显示框架
export QT_QPA_PLATFORM=xcb:tty=/dev/fb0                //采用x11显示框架
(4)运行示例应用
root@ELF1:~# /examples/charts/areachart/areachart
root@ELF1:~# export DISPLAY=:0.0
root@ELF1:~# /examples/charts/areachart/areachart
效果如下:
								
								
								
1530
					