嵌入式Linux--交叉编译安装Qt5.9.1

嵌入式linux 专栏收录该内容
79 篇文章 1 订阅

Qt5 移植到 licheepi zero

前言

下载地址:https://download.qt.io/archive/qt/5.9/5.9.1/single/qt-everywhere-opensource-src-5.9.1.tar.xz

wget https://download.qt.io/archive/qt/5.9/5.9.1/single/qt-everywhere-opensource-src-5.9.1.tar.xz

tar xf qt-everywhere-opensource-src-5.9.1.tar.xz    #这里解压也需要30s左右,别以为死机了。。
cd qt-everywhere-opensource-src-5.9.1

一、准备工作

确保以下软件已安装,

sudo apt-get install xorg-dev libfontconfig1-dev \
libfreetype6-dev libx11-dev libxcursor-dev libxext-dev \
libxfixes-dev libxft-dev libxi-dev libxrandr-dev libxrender-dev

二、配置

1、 解压源代码 qt-everywhere-opensource-src-5.9.1.tar.gz,并进入源代码文件夹

tar xf qt-everywhere-opensource-src-5.9.1.tar.xz    #这里解压也需要30s左右,别以为死机了。。
cd qt-everywhere-opensource-src-5.9.1

2、指定所用平台的 arm 架构以及交叉编译器:

vim 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_RELEASE   += -O2 -march=armv7-a
QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv7-a

include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)

QMAKE_INCDIR += /opt/tslib/include
QMAKE_LIBDIR += /opt/tslib/lib

# modifications to g++.conf
QMAKE_CC                = /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -lts
QMAKE_CXX               = /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -lts
QMAKE_LINK              = /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -lts
QMAKE_LINK_SHLIB        = /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -lts

# modifications to linux.conf
QMAKE_AR                = /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar cqs
QMAKE_OBJCOPY           = /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-objcopy
QMAKE_NM                = /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-nm -P
QMAKE_STRIP             = /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-strip
load(qt_config)

心路历程
 就必须得详细的说交叉编译工具在哪里吧!

3、根据自己的实际需求配置 Qt(此处是使用 tslib 的编译):
编辑一个文件:vim cfg_arm.sh

#!/bin/sh
./configure \
-prefix /opt/qt5.9.1-arm \
-confirm-license \
-opensource \
-shared \
-release \
-make libs \
-xplatform linux-arm-gnueabi-g++ \
-optimized-qmake \
-pch \
-linuxfb \
-qt-libjpeg \
-qt-libpng \
-qt-zlib \
-tslib \
-no-opengl \
-no-sse2 \
-no-openssl \
-no-cups \
-no-glib \
-no-dbus \
-no-xcb \
-no-separate-debug-info \
-I/opt/tslib/include -L/opt/tslib/lib \
-nomake examples -nomake tools -nomake tests -no-iconv \
-tslib \
-I/opt/tslib/include \
-L/opt/tslib/lib \
-recheck-all

心路历程

 开始配置的是 -make examples死活编译不出来,最后群里的一个大佬提醒改成-nomake examples即先不编译出例程,这样倒是可算是编译出来了!

三、编译安装

sudo make -j16
make install

安装成功如下:

sudo make install 
......
/home/qt-everywhere-opensource-src-5.9.1/qtbase/bin/qmake -install qinstall /home/qt-everywhere-opensource-src-5.9.1/qttranslations/translations/qtxmlpatterns_pl.qm /opt/qt5.9.1-arm/translations/qtxmlpatterns_pl.qm
/home/qt-everywhere-opensource-src-5.9.1/qtbase/bin/qmake -install qinstall /home/qt-everywhere-opensource-src-5.9.1/qttranslations/translations/qtxmlpatterns_ru.qm /opt/qt5.9.1-arm/translations/qtxmlpatterns_ru.qm
/home/qt-everywhere-opensource-src-5.9.1/qtbase/bin/qmake -install qinstall /home/qt-everywhere-opensource-src-5.9.1/qttranslations/translations/qtxmlpatterns_sk.qm /opt/qt5.9.1-arm/translations/qtxmlpatterns_sk.qm
/home/qt-everywhere-opensource-src-5.9.1/qtbase/bin/qmake -install qinstall /home/qt-everywhere-opensource-src-5.9.1/qttranslations/translations/qtxmlpatterns_uk.qm /opt/qt5.9.1-arm/translations/qtxmlpatterns_uk.qm
make[2]: Leaving directory '/home/qt-everywhere-opensource-src-5.9.1/qttranslations/translations'
make[1]: Leaving directory '/home/qt-everywhere-opensource-src-5.9.1/qttranslations'
cd qtdoc/ && ( test -e Makefile || /home/qt-everywhere-opensource-src-5.9.1/qtbase/bin/qmake -o Makefile /home/qt-everywhere-opensource-src-5.9.1/qtdoc/qtdoc.pro ) && make -f Makefile install
make[1]: Entering directory '/home/qt-everywhere-opensource-src-5.9.1/qtdoc'
cd doc/ && ( test -e Makefile || /home/qt-everywhere-opensource-src-5.9.1/qtbase/bin/qmake -o Makefile /home/qt-everywhere-opensource-src-5.9.1/qtdoc/doc/doc.pro ) && make -f Makefile install
make[2]: Entering directory '/home/qt-everywhere-opensource-src-5.9.1/qtdoc/doc'
make[2]: Nothing to be done for 'install'.
make[2]: Leaving directory '/home/qt-everywhere-opensource-src-5.9.1/qtdoc/doc'
make[1]: Leaving directory '/home/qt-everywhere-opensource-src-5.9.1/qtdoc'

错误一:

dpaths_unix.o .obj/adler32.o .obj/compress.o .obj/crc32.o .obj/deflate.o .obj/gzclose.o .obj/gzlib.o .obj/gzread.o .obj/gzwrite.o .obj/infback.o .obj/inffast.o .obj/inflate.o .obj/inftrees.o .obj/trees.o .obj/uncompr.o .obj/zutil.o
make[3]: Leaving directory '/home/qt-everywhere-opensource-src-5.9.1/qtbase/src/tools/bootstrap'
make[2]: Leaving directory '/home/qt-everywhere-opensource-src-5.9.1/qtbase/src'
Makefile:48: recipe for target 'sub-src-make_first' failed
make[1]: *** [sub-src-make_first] Error 2
make[1]: Leaving directory '/home/qt-everywhere-opensource-src-5.9.1/qtbase'
Makefile:82: recipe for target 'module-qtbase-make_first' failed
make: *** [module-qtbase-make_first] Error 2

这个错误卡了好几天,没有法子!最后大佬提醒:
configure 时加个 -nomake examples 参数,先不编译examples看看能不能编译过去

四、移植 Qt 到 licheepi 开发板

完成上述步骤后, qt5.9.1 将被安装到/opt/qt5.9.1-arm 中。然后将安装目录/opt/qt5.9.1-arm全部复制到开发板的/opt/目录中,将/opt/tslib中的 tslib目录全部复制到开发板的/opt/中。

五、设置开发板 Qt 环境变量:

vi /etc/bash.bashrc

添加下面内容:

export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CONFFILE=/opt/tslib/etc/ts.conf
export TSLIB_PLUGINDIR=/opt/tslib/lib/ts
export TSLIB_CALIBFILE=/etc/pointercal
export LD_LIBRARY_PATH=/lib:/usr/lib:/opt/tslib/lib:/opt/qt5.9.1-arm/lib
export PATH=/bin:/sbin:/usr/bin/:/usr/sbin:/opt/tslib/bin
export QT_QPA_PLATFORM_PLUGIN_PATH=/opt/qt5.9.1-arm/plugins
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0
export QT_QPA_FONTDIR=/opt/qt5.9.1-arm/lib/fonts
export QT_QPA_GENERIC_PLUGINS=tslib:$TSLIB_TSDEVICE

保存退出后使上面的环境变量生效:

source /etc/bash.bashrc

在QtCreator上编译好一个helloworld拷贝到开发板上去运行。–这里的重点就是需要配置安装上面编译好的目录中的qmake否则是无法编译成功的。

六、在虚拟机上开发的软件

ELF格式文件符号表全解析及readelf命令使用方法

liefyuan@ubuntu:~/Qt /Hiliefyuan/build-Hiliefyuan-Desktop_Qt_5_14_1_GCC_64bit-Debug$ readelf -h Hiliefyuan 
ELF 头:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  类别:                              ELF64
  数据:                              2 补码,小端序 (little endian)
  版本:                              1 (current)
  OS/ABI:                            UNIX - System V
  ABI 版本:                          0
  类型:                              EXEC (可执行文件)
  系统架构:                          Advanced Micro Devices X86-64
  版本:                              0x1
  入口点地址:               0x402940
  程序头起点:          64 (bytes into file)
  Start of section headers:          1052544 (bytes into file)
  标志:             0x0
  本头的大小:       64 (字节)
  程序头大小:       56 (字节)
  Number of program headers:         9
  节头大小:         64 (字节)
  节头数量:         40
  字符串表索引节头: 37
liefyuan@ubuntu:~/Qt /Hiliefyuan/build-Hiliefyuan-Desktop_Qt_5_14_1_GCC_64bit-Debug$ cd ..
liefyuan@ubuntu:~/Qt /Hiliefyuan$ cd build-Hiliefyuan-v3s_toolchain-Release/
liefyuan@ubuntu:~/Qt /Hiliefyuan/build-Hiliefyuan-v3s_toolchain-Release$ readelf -h Hiliefyuan 
ELF 头:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  类别:                              ELF32
  数据:                              2 补码,小端序 (little endian)
  版本:                              1 (current)
  OS/ABI:                            UNIX - System V
  ABI 版本:                          0
  类型:                              EXEC (可执行文件)
  系统架构:                          ARM
  版本:                              0x1
  入口点地址:               0x1285d
  程序头起点:          52 (bytes into file)
  Start of section headers:          17668 (bytes into file)
  标志:             0x5000402, Version5 EABI, hard-float ABI, <unknown>
  本头的大小:       52 (字节)
  程序头大小:       32 (字节)
  Number of program headers:         8
  节头大小:         40 (字节)
  节头数量:         40
  字符串表索引节头: 37

七、错误提示

1、Helloworld例程报错:error while loading shared libraries: /usr/lib/libts.so.0: file too short

# ./Hiliefyuan
./Hiliefyuan: error while loading shared libraries: /usr/lib/libts.so.0: file too short

办法一:重新上电后就没了
这个是tslib库报错
程序没找到tslib库的libts.so文件(文件路径在/tslib/lib里)
可以在/etc/profile里添加

vi /etc/profile

LD_LIBRARY_PATH=/usr/local/tslib/lib:$LD_LIBRARY_PATH
export QT_DEBUG_PLUGINS=1

source /etc/profile
程序运行的时候会打印详细信息

办法二:可以维持重新上电后还需要source一下????
在/etc/bash.bashrc里面添加也可以

  • 1
    点赞
  • 3
    评论
  • 5
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值