本文记录对龙芯2K进行qt5.13.1版本的移植。
本文中对于tslib的安装不做讲解,使用了QT4进行核心板开发的童鞋一般情况下,应该已经安装好了tslib了,直接使用就行。
我所用到的编译环境如下:
交叉编译链工具:glibc-gcc-4.9.x-mips32
QT源码:qt-everywhere-opensource-src-5.13.1.tar.xz
为了更直观,特别说一下QT4和QT5在编译中的主要区别,以QT-4.8.6和QT-5.7.1的源码为例:
1、将源码包解压缩以后,最直观的区别是,存放交叉编译用的qmake文件的,mkspecs文件夹,在QT4中是放置于根目录下,而在QT5当中,则是存放在根目录的qtbase文件夹下。
2、在mkspecs的目录下,QT4中有linux-mips-g++文件夹,存放qmake文件,在QT5中没有这个文件夹。
qmake是一个描述构建过程的文件,将指定编译过程中所使用的编译工具。因此,在QT5中也必然需要这个文件。
下面是正文内容。
一、创建Linux-mips-g++文件夹
#tar -xvf qt-everywhere-opensource-src-5.13.1.tar.xz
#cd qt-everywhere-opensource-src-5.13.1
#cd qtbase/mkspecs
#cp -rf linux-arm-gnueabi-g++/ linux-mips-g++
//用目录下原有的linux-arm-gnueabi-g++文件夹打个样,复制并修改文件夹名为linux-mips-g++在里面直接修改,顺便也将qplatformdefs.h复制了过来
下面修改qmake的内容。只列举重点内容
#
# 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 = mips64el-linux-gcc
QMAKE_CXX = mips64el-linux-g++
QMAKE_LINK = mips64el-linux-g++
QMAKE_LINK_SHLIB = mips64el-linux-g++
# modifications to linux.conf
QMAKE_AR = mips64el-linux-ar cqs
QMAKE_OBJCOPY = mips64el-linux-objcopy
QMAKE_NM = mips64el-linux-nm -P
QMAKE_STRIP = mips64el-linux-strip
load(qt_config)
二、创建配置文件
接下去就是一个套路了,configure,make,make install三步走。
回到该安装包的根目录下。这时候根目录下有一个configure文件,需要进行配置,生成Makefile。我的习惯是生成一个脚本文件进行配置。
在脚本文件中添加如下内容:
#!/bin/sh
./configure \
-v \
-prefix /opt/qt-5.7.1-mipsel-tslib \
-confirm-license \
-opensource \
-make libs \
-xplatform linux-mips-g++ \
-optimized-qmake \
-pch \
-no-sse2 \
-no-sse3 \
-no-ssse3 \
-no-sse4.1 \
-no-sse4.2 \
-pkg-config \
-qt-libjpeg \
-qt-libpng \
-qt-zlib \
-skip qt3d \
-skip qtcanvas3d \
-skip qtpurchasing \
-skip qtvirtualkeyboard \
-alsa \
-no-opengl \
-no-openssl \
-no-cups \
-no-glib \
-no-dbus \
-no-xcb \
-no-separate-debug-info \
-nomake examples -nomake tools -nomake tests -no-iconv \
-tslib \
-I/opt/tslib-mipsel/include \
-L/opt/tslib-mipsel/lib
exit
执行./autoconfigure.sh,遇到错误:
vi configure
: set ff=unix
:wq
继续执行./autoconfigure.sh:
./configure: 49: exec: /home/ww/qt/qt-everywhere-src-5.13.0/qtbase/configure: not found
vi qtbase/configure
: set ff=unix
:wq
遇到错误:
ERROR: Feature ‘pkg-config’ was enabled, but the pre-condition
‘tests.pkg-config’ failed
缺少依赖库,安装:sudo apt-get install libclang-dev
安装后继续报错:
Note: Also available for Linux: linux-clang linux-icc
Note: -optimized-tools is not useful in -release mode.
Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.
WARNING: QDoc will not be compiled, probably because libclang could not be located. This means that you cannot build the Qt documentation.
Either ensure that llvm-config is in your PATH environment variable, or set LLVM_INSTALL_DIR to the location of your llvm installation.
On Linux systems, you may be able to install libclang by installing the libclang-dev or libclang-devel package, depending on your distribution.
On macOS, you can use Homebrew's llvm package.
On Windows, you must set LLVM_INSTALL_DIR to the installation path.
WARNING: gperf is required to build QtWebEngine.
WARNING: bison is required to build QtWebEngine.
WARNING: flex is required to build QtWebEngine.
ERROR: Feature 'pkg-config' was enabled, but the pre-condition 'tests.pkg-config' failed.
ERROR: Feature 'alsa' was enabled, but the pre-condition 'config.unix && !config.qnx && libs.alsa' failed.
配置是个很繁琐的过程,配置文件选择有问题,会出现各种报错,焦头烂额,因此,最好能将相关配置项都有一个较为直观的了解,不然会一头雾水。如果你不会配置,就尽量使用我的上述配置,至少能保证能用。
然后就是三步走,运行脚本文件,make,make install。
#./autoconfigure.sh
#make -j4
#make install
每个人的系统环境有些区别,make中可能碰到各种可能的情况,请不要放弃,慢慢磨,总能成功的。
三、龙芯1B配置环境变量
具体怎么将lib和plugin文件放入龙芯1B核心板,我就不说了,重点看环境变量的配置。需要将主机上的 /opt/qt-5.7.1-mipsel-tslib 目录中的lib和plugins文件夹复制到核心板上。
#vi /etc/profile
修改如下内容:
export QT_DEBUG_PLUGINS=1 //将可执行程序启动过程中的内容打印出来,方便排查故障。
export QTDIR_QT5=/mnt/mmc_sd/qt-5.7.1-libs //指向你刚复制进去的文件目录。
export QT_QPA_PLATFORM_PLUGIN_PATH=$QTDIR_QT5/plugins
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0
export QT_QPA_FONTDIR=/lib/fonts
export QT_QPA_GENERIC_PLUGINS=tslib
export QT_QPA_FB_TSLIB=1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TSLIB_ROOT/lib:$QTDIR_QT5/lib
export TSLIB_CONSOLEDEICE=none
其余部分与 QT4
环境下没区别。
然后就是运行你的程序的时候,不需要加-qws,如下:
#./test
有时候运行的时候,会有Illegal instruction (非法指令)的报错,这时候多试着运行几遍可能就可以了。
关于为什么要进行上述修改,包括在核心板环境变量中,取消了QWS的相关配置,添加了QPA的相关配置。
Qt5与Qt4对比有很大的改变,其最大的特性在于模块化,并且很明显的是不再见到Qt4用到的qws,Qt5新增了QPA系统,基于QPA使得Qt5移植到一个新平台非常简单而又具有极强的底层扩展能力;同时,C++11 也获得全面支持,使用 C++11 新特性更为方便。
另外,这时候运行的界面会发现没有边框,用linuxfb方式的运行的QT是没有窗体边框的,这是qt5的一个特点,似乎是其为了更好的转移到手机等移动终端。
在配置环境变量的过程中,有人会发现我的一个路径中有mmc_sd这个目录,这是我将QT5的库文件等放到了外置的tf卡下,原因很简单,自带的存储不够用了。在使用tf卡之前,需要先将tf卡格式化为ext4,不然在进行一些带链接的复制操作或者别的操作的时候,会报错。
挂载的命令如下:
#mount -t ext4 /dev/mmcblk0p1 /mnt/mmc_sd/
//注意,mmcblk0p1,b和k之间是L的小写,最后那个是阿拉伯数字1。
可以将这句话写入 /etc/init.d/rcS 中,这样实现每次开机自动挂载。