
本编介绍如何在嵌入式linux开发板上配置qt运行环境,并进行qt程序运行测试。

tslib之前在测试触摸屏的时候使用过,这里再来记录一下编译过程。
下载tslib库的源码:https://github.com/libts/tslib/tags
将下载的源码拷贝到ubuntu虚拟机中,然后解压:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">tar xvf tslib-1.21.tar.bz2</code>
编译 tslib 的时候需要先在 ubuntu 中安装一些文件:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">sudo apt-get install autoconf sudo apt-get install automake sudo apt-get install libtool</code>
在 ubunt中创建一个名为“tslib”的目录存放编译结果,然后执行以下指令进行编译:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">./configure --host=arm-linux-gnueabihf ac_cv_func_malloc_0_nonnull=yes --cache-file=arm-linux.cache -prefix=/home/xxpcb/myTest/imx6ull/otherlib/tslib-2/tslibmakemake install</code>
编译完成后,make install会将编译成果复制到指定的tslib目录中:

将tslib文件夹先整个打包为arm-tslib.tar.bz2文件,后面移植到开发板时用:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">tar -jcf arm-tslib.tar.bz2 tslib</code>
下载地址:https://download.qt.io/archive/qt/5.15/5.15.2/single/

将下载的qt-everywhere-src-5.15.2.tar.xz拷贝到Ubuntu中,然后解压:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">tar -xvf qt-everywhere-src-5.15.2.tar.xz</code>

修改qtbase/mkspecs/linux-arm-gnueabi-g++/中的qmake.conf文件
这个文件默认的内容是:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">## qmake configuration for building with arm-linux-gnueabi-g++#MAKEFILE_GENERATOR = UNIXCONFIG += incrementalQMAKE_INCREMENTAL_STYLE = sublibinclude(../common/linux.conf)include(../common/gcc-base-unix.conf)include(../common/g++-unix.conf)# modifications to g++.confQMAKE_CC = arm-linux-gnueabi-gccQMAKE_CXX = arm-linux-gnueabi-g++QMAKE_LINK = arm-linux-gnueabi-g++QMAKE_LINK_SHLIB = arm-linux-gnueabi-g++# modifications to linux.confQMAKE_AR = arm-linux-gnueabi-ar cqsQMAKE_OBJCOPY = arm-linux-gnueabi-objcopyQMAKE_NM = arm-linux-gnueabi-nm -PQMAKE_STRIP = arm-linux-gnueabi-stripload(qt_config)</code>
修改成如下:

查看编译选项,输入./configure -help 指令,查看可配置选项
代码语言:javascript代码运行次数:0运行复制<code class="javascript">./configure -help</code>

可以看到配置项有很多,因此可以使用一个配置脚本来进行配置。
编写一个autoconfigure.sh文件,然后根据自己的情况,写入如下配置:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">./configure -prefix /home/xxpcb/myTest/imx6ull/otherlib/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/xxpcb/myTest/imx6ull/otherlib/tslib-2/tslib/include \-L/home/xxpcb/myTest/imx6ull/otherlib/tslib-2/tslib/lib \-recheck-all</code>
注意其中3处是自己的配置路:
1 /home/xxpcb/myTest/imx6ull/otherlib/qt/qt-everywhere-src-5.12.9/arm-qt 为编译输出路径。
2 /home/xxpcb/myTest/imx6ull/otherlib/tslib-2/tslib/include 为tslib 头文件路径。
3 /home/xxpcb/myTest/imx6ull/otherlib/tslib-2/tslib/lib 为tslib相关库文件路径。
其它一些参数的含义:
-opensource:构建Qt的开源版本-release:使用release版本的Qt-xplatform linux-arm-gnueabi-g++:指定编译器-skip qt3d:跳过Qt的3d-make libs:编译要用到的库-make examples:编译生成Qt的例程代码-nomake tools:不生成Qt的工具-no-openssl:不使用openssl2.4 编译配置前需要先安装 g++
代码语言:javascript代码运行次数:0运行复制<code class="javascript">sudo apt-get install g++</code>
赋予脚本可执行权限,然后执行 autoconfigure.sh
代码语言:javascript代码运行次数:0运行复制<code class="javascript">chmod +x autoconfigure.sh./autoconfigure.sh</code>

运行完成之后:

然后就可以执行make指令进行编译了。
编译大约需要十几到几十分钟。

编译完成之后,再执行make install进行安装,安装之后就可以看到arm-qt文件中的内容了:

将qrm-qt文件夹先整个打包为arm-qt.tar.bz2文件,后面移植到开发板时用:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">tar -jcf arm-qt.tar.bz2 arm-qt</code>
make编译时可能会遇到编译出错
情况1:我遇到过下面这种:
这种情况是因为我的ubuntu虚拟机空间不够用了,解决方法就是给虚拟器扩容,具体操作过程见:VirtualBox虚拟机Ubuntu扩容记
情况2:编译最新版本的QT源码报错
使用Qt最新版本5.15.2编译报错,暂未找到解决方法,所以我先用5.12.9版本的Qt。
3 开发板上配置Qt环境3.1 复制tslib和Qt的编译文件将之前打包的arm-tslib.tar.bz2和arm-qt.tar.bz2压缩包复制到板子中,可以先复制到nfs网络位置,然后解压到/usr/lib 目录下,解压后开删除无用的压缩包。
这是对arm-qt的操作步骤:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">cp arm-qt.tar.bz2 ~/myTest/nfs/rootfs/usr/libcd ~/myTest/nfs/rootfs/usr/lib/tar xf arm-qt.tar.bz2rm arm-qt.tar.bz2</code>
arm-tslib复制与解压过程类似。
3.2 设置开发板的环境变量编辑/etc/profile,写入如下内容:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">export TSLIB_ROOT=/usr/lib/arm-tslib export TSLIB_CONSOLEDEVICE=none export TSLIB_FBDEVICE=/dev/fb0 export TSLIB_TSDEVICE=/dev/input/event1 export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts export TSLIB_CALIBFILE=/etc/pointercal export LD_PRELOAD=$TSLIB_ROOT/lib/libts.soexport QT_ROOT=/usr/lib/arm-qt export QT_QPA_GENERIC_PLUGINS=tslib:/dev/input/event1 export QT_QPA_FONTDIR=/usr/share/fonts export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0 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_FB_TSLIB=1</code>
然后使该配置立即生效:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">source /etc/profile</code>
Qt的编译文件中,自带的Qt的一些例子,可以先来在板子上运行这些例子看看Qt程序能否在板子上正常运行。
这是运行其中的一个程序:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">/usr/lib/arm-qt/examples/widgets/animation/animatedtiles/animatedtiles</code>
以上就是嵌入式Linux-Qt环境搭建的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号