源作者:软核改造祝融叔
如何在开发板运行程序事情的源头,是我手头的AIO-3288开发板,基于RK3288的arm32 CPU,开发板产家的ubuntu 18.04 固件,默认的安装Qt版本是5.9.5 ,它的glibc库基于 2.27.
但是产家给的Qt 开发库是5.14.2版本,它基于glibc 2.29,所以编译出来的程序是无法运行的,一运行就提示glibc 版本太低
/lib/arm-linux-gnueabihf/libm.so.6: version `GLIBC_2.29' not found (required by /usr/lib/libQt5Widgets.so.5)
因此我有如下四种选择
一.在开发板升级 glibc 2.29
二.整体升级到ubuntu 20.04固件
三.在RK3288开发板下载完整的Qt 开发环境,完全在板子上开发
三.在PC机上编译Qt 5.9.5的开发库.
第一方案相当于边开车边修发动机,操作不好整个系统就挂了,我在刷了5次机后放弃这个方案。
第二方案相当于干了开发板厂家的活,需要完整地编译整个根文件系统,耗时且成功未知,我另一块RK3399开发板产家已经升级到ubuntu 20,它的可以直接用Qt 5.14.2开发库,但它是ARM64内核,无法用在RK3288的arm32上.还是等产家的新固件吧。
第三种方案是的板子上用apt-get 下载完整 的Qt开发环境 (动态库,头文件,编译工具,QtCreator等。用如下指令
sudo apt-get install qt5-default
sudo apt-get install qtcreator
但我下载失败,即便成功,在资源有限的开发板开发复杂项目也是效率极低,这一方案放弃.
所以最终的方案就是直接在桌面的ubuntu 上编译Qt 5.9.5的开发库.
注意这里只需要编译开发库编译应用程序,而运行环境仍然采用开发板自带的环境。只要两者编译器和版本号一致,应用程序就能直接运行。同时只要保证编译Qt接口一致就行了,至于底层实现是运行库的事情,所以怎么编译简单怎么来。
编译准备
下载开发环境
sudo apt-get install gcc-arm-linux-gnueabihf
sudo apt-get install g++-arm-linux-gnueabihf
这两条指令分别下载arm-linux-gnueabi-gcc /arm-linux-gnueabi-g++两套环境.
如果无法下载,可手动下载后解压安装
gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf.tar.xz
编译udev 库,请参考我另一篇文章
这里不编译openssl库,所以也不编译它
Qt 5.9.5 源码下载如下文件 qt-everywhere-opensource-src-5.9.5.tar.xz
解压源码
tar xvfqt-everywhere-opensource-src-5.9.5.tar.xz
cd qt-everywhere-opensource-src-5.9.5
在源码目录,指定此次Qt使用的编译器 arm-linux-gnueabi-g++,这个配置文件是
qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf
把里面所有编译器改成 arm-linux-gnueabi 前缀,修改后内容如下
#
# qmake configuration for building with arm-linux-gnueabihf-g++
#
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
include(https://www.whysem.com/common/linux.conf)
include(https://www.whysem.com/common/gcc-base-unix.conf)
include(https://www.whysem.com/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)
生成编译Makefile
这是用configure 工具生成,因为Qt 选项太多,这是不同环境,不同硬件调整最多地方,需要开发者自行反复调试。
我成功编译通过经过如下configure 指令如下
https://www.whysem.com/a/configure -opensource -confirm-license -prefix $PWD/https://www.whysem.com/qt-release
-opensource -nomake tests -nomake examples
-xplatform linux-arm-gnueabi-g++
-qt-libjpeg -qt-libpng -qt-pcre -qt-zlib -qt-harfbuzz
-no-icu -no-openssl -no-opengl -no-tslib -no-sql-psql
-qt-sqlite -qt-freetype -no-eglfs -no-iconv -no-evdev -no-cups
-skip qtwayland -skip qtmultimedia -skip qtpurchasing -skip qtlocation
这里--prefix是安装目录,表示安装在上一级目录 qt-release目录下
如何在开发板运行程序中-no-openssl 是不编译openssl库,
-xplatform linux-arm-gnueabi-g++ 就表示引用我们上面修改的qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf 文件
其余可以选择 configure --help 查看具体解释,其中 -no打头表示不编译, -qt 表示使用Qt 源码目录下第三方库源码 -skip 是移正某个非核心库。
实际有几个大的库一般用不上,比如 qtScript 等,QtWebKit等,如果想节约时间可以增加w从如下选项选择加入到configure语句,这
-skip qt3d
-skip qtactiveqt
-skip qtandroidextras
-skip qtcanvas3d
-skip qtcharts
-skip qtconnectivity
-skip qtdatavis3d
-skip qtdeclarative
-skip qtdoc
-skip qtgamepad
-skip qtgraphicaleffects
-skip qtlocation
-skip qtmacextras
-skip qtmultimedia
-skip qtnetworkauth
-skip qtpurchasing
-skip qtquickcontrols
-skip qtquickcontrols2
-skip qtremoteobjects
-skip qtscript
-skip qtscxml
-skip qtsensors
-skip qtserialbus
-skip qtserialport
-skip qtspeech
-skip qtsvg
-skip qttools
-skip qttranslations
-skip qtvirtualkeyboard
-skip qtwayland
-skip qtwebchannel
-skip qtwebengine
-skip qtwebglplugin
-skip qtwebsockets
-skip qtwebview
-skip qtwinextras
-skip qtxmlpatterns
-skip qtx11extras
生成成功后,直接在源码目录
编译
make
安装
make install
配置开发环境QtCreater
安装QtCreator 有两种方法,
一种是在线安装
sudo apt-get install qtcreator
另一种是下载完整Linux 安装程序,安装一个桌面版Qt 5.9.5和QtCreator
下载这个安装文件,并双击运行
qt-opensource-linux-x64-5.9.5.run
最后均会运行一个图形的开发环境QtCreator
选择主菜单[Tools]-[Options]-[Build & Run]
1.配置C编译器 arm-linux-gnueabi-gcc
2.配置C++编译器 arm-linux-gnueabi-g++
3.配置Qt库版本,选择刚编译的qmake
4.最后新建一个Qt kits 来分别使用前面定义编译和Qt版本
这里我取名为 rk3288 Qt 5.9.5
开发项目时,选择rk3288 Qt 5.9.5 进行编译即是生成RK3288相应程序
最看一下在开发板上运行效果,完全能正常运行,至此整个环境搭建成功
,