• imx6ull应用开发 | 移植Qt 5.12.9到imx6ull并搭建qt creator开发环境


    环境说明

    • 编译器:arm-linux-gnueabihf-gcc 7.5.0
    • OS:ubuntu 20.04

    一、下载qt源码

    qt下载地址:https://download.qt.io/archive/qt/5.12/5.12.9/single/

    wget https://download.qt.io/archive/qt/5.12/5.12.9/single/qt-everywhere-src-5.12.9.tar.xz
    
    • 1

    下载后解压:

    xz -d qt-everywhere-src-5.12.9.tar.xz
    tar -xf qt-everywhere-src-5.12.9.tar
    
    • 1
    • 2

    解压后的目录大小2.8G,内容如下:

    二、交叉编译qt源码

    1. 修改qmake.conf

    修改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
    
    QT_QPA_DEFAULT_PLATFORM = linuxfb
    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
    
    include(../common/linux.conf)
    include(../common/gcc-base-unix.conf)
    include(../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)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    2. 配置编译选项

    添加autoconfigure.sh脚本文件:

    ./configure -prefix /home/mculover666/develop/imx6ull/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/mculover666/develop/imx6ull/tool/tslib-1.22-build/include \
    -L/home/mculover666/develop/imx6ull/tool/tslib-1.22-build/lib \
    -recheck-all
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61

    给脚本可执行权限:

    sudo chmod +x autoconfigure.sh
    
    • 1

    执行脚本开始配置:

    ./autoconfigure.sh
    
    • 1

    3. 编译

    make -j16
    
    • 1

    4. 安装

    make install
    
    • 1

    安装完之后查看安装内容和大小:

    将安装的文件夹打包备份:

    tar -jcf armhf-qt-5.12.9.tar.bz2 arm-qt
    
    • 1

    三、移植qt到开发板rootfs

    1. 拷贝qt安装文件

    将上一节的压缩包armhf-qt-5.12.9.tar.bz2拷贝到跟文件下系统,解压:

    tar xf armhf-qt-5.12.9.tar.bz2 -C /usr/lib
    
    • 1

    2. 配置Qt5的环境变量

    export 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  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    额外配置tslib库的地址:

    export LD_PRELOAD=$TSLIB_ROOT/lib/libts.so
    
    • 1

    环境变量生效:

    source /etc/profile
    
    • 1

    3. 测试

    运行demo:

    cd /usr/lib/arm-qt/examples/widgets/widgets/digitalclock
    ./digitalclock
    
    • 1
    • 2

    效果如下:

    四、搭建Qt Creator开发环境

    1. 下载Qt Creator

    下载地址:https://download.qt.io/archive/qt/5.12/5.12.9/

    wget https://download.qt.io/archive/qt/5.12/5.12.9/qt-opensource-linux-x64-5.12.9.run
    
    • 1

    2. 安装Qt Creator

    添加可执行权限:

    sudo chmod +x qt-opensource-linux-x64-5.12.9.run
    
    • 1

    执行,就有了一个安装界面:

    sudo ./qt-opensource-linux-x64-5.12.9.run
    
    • 1



    3. 配置Qt Creator

    启动Qt Creator:

    /opt/Qt5.12.9/Tools/QtCreator/bin/qtcreator.sh &
    
    • 1


    (1)配置qmake为之前交叉编译安装的:

    (2)配置gcc编译器

    (3)配置Kits

    4. 新建工程



    两个开发套件都选:

    添加一个控件:

    在电脑上运行的效果:

    选择arm平台编译套件:

    编译工程:

    找到编译出的可执行文件:

    拷贝到开发板上运行,效果如下:

    开启调试日志,提示缺少字体,添加字体后,效果如下:

    五、移植遇到的问题汇总

    1. 缺少python命令

    问题描述:make install的时候,安装qml提示缺少python。

    问题分析:ubuntu20.04里有python 3.8,需要python3才行,没有默认的python命令,所以造一个软链接即可。

    sudo ln -s /usr/bin/python3 /usr/bin/python
    
    • 1

    再次执行make install即可。

    2. 运行demo后提示缺少libts.so库

    问题描述:执行demo后没有任何反应。

    问题定位:开启qt debug日志输出,进一步找出问题所在位置。

    export QT_DEBUG_PLUGINS=1
    
    • 1

    开启之后看到出错位置,提示缺少libts.so.0库:

    问题解决: 在环境变量里添加该库的配置。

    export LD_PRELOAD=$TSLIB_ROOT/lib/libts.so
    
    • 1

    重新生效环境变量,再次执行demo,正常运行。

    3. 缺少字体

    在开发板rootfs上创建/usr/share/fonts目录,将字库拷贝进去:

    创建 /etc/fonts/fonts.conf 文件,加入以下内容:

    
    <!-- Font directory list -->
    
            <dir>/usr/share/fonts</dir>
    
            <dir prefix="xdg">fonts</dir>
            <!-- the following element will be removed in the future -->
            <dir>~/.fonts</dir>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    参考资料

  • 相关阅读:
    预训练词嵌入Pretrained Word Embeddings
    js 数组合并的方式
    嵌入式驱动学习第三周——Linux内核中的继承思想
    RT-DETR算法优化改进:Backbone改进 | EMO,结合 CNN 和 Transformer 的现代倒残差移动模块设计 | ICCV2023
    dockerfile创建镜像与容器卷
    【Vue】v-for中:key中item.id与Index使用的区别
    机器人控制算法四之迭代法求解四轴机器人逆解
    DPDK-A3: KVM使用SRIOV和虚机使用DPDK
    H41H-40C法兰止回阀型号解析
    JWT简介& JWT结构& JWT示例& 前端添加JWT令牌功能& 后端程序
  • 原文地址:https://blog.csdn.net/Mculover666/article/details/126307077