交叉工具链使用phytium-linux-buildroot源码制作的工具链,源码下载地址:
https://gitee.com/phytium_embedded/phytium-linux-buildroot
制作buildroot文件系统:
(如果已经有现成的工具链和根文件系统,使用现成的就行,不需要再制作。)
./support/kconfig/merge_config.sh configs/phytium_defconfig
make -j$(nproc)
make sdk -j$(nproc)
编译完成后,在buildroot源码目录的output/images/目录生成aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz交叉工具链和rootfs.tar根文件系统。
安装工具链:
sudo tar -xf aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz -C /opt/
cd /opt/aarch64-buildroot-linux-gnu_sdk-buildroot
sudo ./relocate-sdk.sh
获取qt-5.3.2源码:
https://download.qt.io/new_archive/qt/5.3/5.3.2/single/
解压后修改源码:
1. 修改源码目录下的qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf文件,arm-linux-gnueabi-字段修改为aarch64-none-linux-gnu-,如下:
#
# qmake configuration for building with aarch64-none-linux-gnu-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 = aarch64-none-linux-gnu-gcc
QMAKE_CXX = aarch64-none-linux-gnu-g++
QMAKE_LINK = aarch64-none-linux-gnu-g++
QMAKE_LINK_SHLIB = aarch64-none-linux-gnu-g++
# modifications to linux.conf
QMAKE_AR = aarch64-none-linux-gnu-ar cqs
QMAKE_OBJCOPY = aarch64-none-linux-gnu-objcopy
QMAKE_NM = aarch64-none-linux-gnu-nm -P
QMAKE_STRIP = aarch64-none-linux-gnu-strip
load(qt_config)
2. 修改qtbase/mkspecs/common/gcc-base.conf文件
解决编译错误:error: ‘std::tr1’ has not been declared
(参考Qt编译 error: ‘std::tr1’ has not been declared-CSDN博客)
QMAKE_CXXFLAGS += $$QMAKE_CFLAGS
修改为
QMAKE_CXXFLAGS += $$QMAKE_CFLAGS -std=gnu++98
交叉编译:
cd qt-everywhere-opensource-src-5.3.2
sudo su
export PATH=/opt/aarch64-buildroot-linux-gnu_sdk-buildroot/bin:$PATH
./configure -prefix /media/ufo/data/arm/qt/qt-5.3.2 -release -linuxfb -opensource -optimized-qmake -xplatform linux-arm-gnueabi-g++ -no-opengl -skip qtdeclarative -no-iconv -no-openssl
make -j$(nproc)
make install
这里使用sudo su进入root用户进行交叉编译,否则会报aarch64-none-linux-gnu-gcc找不到的错误。
如果不想用sudo su,可以修改qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf文件,aarch64-none-linux-gnu-使用完整的路径,例如
QMAKE_CC = /opt/aarch64-buildroot-linux-gnu_sdk-buildroot/bin/aarch64-none-linux-gnu-gcc
板卡上运行qt例程:
交叉编译成功后在/media/ufo/data/arm/qt/qt-5.3.2目录下生成qt二进制文件、库、例程、头文件等文件。
1. 复制lib、examples、plugins目录到板卡根文件系统的/home/qt-5.3.2目录
2. 修改板卡根文件系统的/etc/profile文件,添加:
# qt-lib environment variables
export QT_ROOT=/home/qt-5.3.2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$QT_ROOT/lib/
export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0
export QT_QPA_FONTDIR=$QT_ROOT/lib/fonts
启动板卡进入系统后,执行例程:
/usr/lib/qt/examples/gui/analogclock/analogclock
后记
qt-5.3.2并未添加aarch64的支持,使用命令查看交叉工具链的gcc版本
$aarch64-none-linux-gnu-gcc --version
aarch64-none-linux-gnu-gcc (GNU Toolchain for the A-profile Architecture 10.2-2020.11 (arm-10.16)) 10.2.1 20201103
Copyright © 2020 Free Software Foundation, Inc.
可以看到是64位的版本10.2,目前可以用于编译qt-5.3.2,运行例程也正常。
Linux FB控制台光标闪烁问题
Linux FB控制台的光标默认不停闪烁,影响到QT界面,可以通过以下方式关闭或开启FB控制台的光标闪烁:
关闭:
echo 0 > /sys/class/graphics/fbcon/cursor_blink
开启:
echo 1 > /sys/class/graphics/fbcon/cursor_blink