移植qt5.6.0到armv7 <完整过程>

本文详细记录了Qt5.6.0移植到ARMv7平台的全过程,包括环境搭建、软件安装及编译配置,特别关注交叉编译工具链的设置与调试。

移植qt5.6.0到armv7 <完整过程>

概述:本log记录移植qt的整个过程,包括从安装虚拟机到最后编译成功,因为其中任何一个细节都可能导致移植失败


目录

环境

环境介绍

  • 操作系统:win7(64)
  • 虚拟机:vmware12
  • 虚拟系统:Linux ubuntu 3.19.0-25-generic
  • #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

环境搭建

  1. 在win7主机中安装vmware12 #基本上vm10以上就可以
  2. 在vm12中虚拟出ubuntu14.04 x64 #我用的ubuntu镜像是ubuntu14.04 64位的。这个过程自行百度
    注意:内存最好1G以上,cpu最好分配4核,也不是越高越好,但是太低影响编译速度
  3. 安装好ubuntu后,修改/etc/apt/source.list 源(源内容自行百度),apt-get update;apt-get upgrade
    注意:为什么要加这条内容?因为以后可能要用到一些软件,依赖关系和版本都会受到更新的影响

下载软件:

下载以下软件包
1、交叉编译工具连
    sudo apt-get install g++-arm-linux-gnueabi
    sudo apt-get install gcc-arm-linux-gnueabi
2、tslib1.4.tar.gz
3、qt-everywhere-opensource-src-5.6.0-alpha.tar.gz

安装

安装交叉编译工具

如果自己有特殊编译链的需求,或者觉得自己是高手,那就随意从网上手动下载安装吧,这里采用debian提供的自动安装,不用考虑依赖关系和环境变量
sudo apt-get install g++-arm-linux-gnueabi
sudo apt-get install gcc-arm-linux-gnueabi
快准狠

安装tslib1.4.tar.gz

# sudo apt-get install automake;autoconf;libtool
# ./autogen.sh
# echo "ac_cv_func_malloc_0_nonnull=yes" >arm-linux.cache
# ./configure --host=arm-linux-gnueabi  --cache-file=arm-none-linux-gnueabi.cache --enable-inputapi=no  --prefix=/opt/tslib1.4
# make
# make install

注意:
第三条 echo命令会生成cache文件,不可缺少,因为没有这个文件的内容,编译出错:找不到 rc_malloc函数等错误。
第四条命令中的–prefix= 指定生成库的位置,这个位置自己记住,因为要在安装qt-everywhere-opensource-src-5.6.0-alpha.tar.gz时用到

安装qt-everywhere-opensource-src-5.6.0-alpha.tar.gz

首先,vim qt-everywhere-opensource-src-5.6.0/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

#一下内容具体含义请查看官方文档,我的板子是beaglebone black,所以arch=armv7-a mtune=cortex-a8 
QT_QPA_DEFAULT_PLATFORM = linuxfb
QMAKE_CFLAGS  += -msoft-float -D__GCC_FLOAT_NOT_NEEDED -march=armv7-a -mtune=cortex-a8
QMAKE_CXXFLAGS += -msoft-float -D__GCC_FLOAT_NOT_NEEDED -march=armv7-a -mtune=cortex-a8

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

#交叉编译工具链,自行修改成自己的,在命令行中输入#arm- 加tab键,打印出来的就是自己的工具链名字。后缀的-lts意思是加上ts库,也就是tslib库
# modifications to g++.conf
QMAKE_CC                = arm-linux-gnueabi-gcc -lts
QMAKE_CXX               = arm-linux-gnueabi-g++ -lts
QMAKE_LINK              = arm-linux-gnueabi-g++ -lts
QMAKE_LINK_SHLIB        = arm-linux-gnueabi-g++ -lts

#同上
# modifications to linux.conf
QMAKE_AR                = arm-linux-gnueabi-ar cqs
QMAKE_OBJCOPY           = arm-linux-gnueabi-objcopy
QMAKE_NM                = arm-linux-gnueabi-nm -P
QMAKE_STRIP             = arm-linux-gnueabi-strip
load(qt_config)

#这个位置就是编译tslib时的prefix位置,自己设置
QMAKE_INCDIR=/opt/tslib1.4/include/
QMAKE_LIBDIR=/opt/tslib1.4/lib/

然后1,vim autoconfig.sh

#!/bin/sh

./configure \
    -verbose    \
    -prefix /opt/qt-5.6.0 \
    -confirm-license    \
    -opensource -release    \
    -make libs  \
    -xplatform linux-arm-gnueabi-g++    \
    -optimized-qmake    \
    -linuxfb    \
    -pch    \
    -qt-sql-sqlite  \
    -qt-libjpeg \
    -qt-libpng  \
    -qt-zlib    \
    -tslib  \
    -no-opengl  \
    -no-sse2    \
    -no-openssl \
    -no-nis \
    -no-cups    \
    -no-glib    \
    -no-dbus    \
    -no-xcb \
    -no-xcursor -no-xfixes -no-xrandr -no-xrender   \
    -no-separate-debug-info \
    -make examples -nomake tools -nomake tests -no-iconv    \
    -I/opt/tslib1.4/include \
    -L/opt/tslib1.4/lib

这个文件的编写参考configure -help 的说明。我只说需要注意的地方

  1. 一定要看configure -help的配置说明,因为这些配置决定了你编译出来的qt库需要具备那些功能,例如使用支持zlib、sqlit、3d等等
  2. 在写这个autoconfig.sh时,不要直接复制粘贴我的,请自行手打。(空格和tab啊,消耗了半天时间,血的教训)

然后2,# ./autoconfig.sh
然后3,# make
然后4,# 上个厕所,喝杯水,或者喝杯水,上个厕所
最后,# make insatll

拷贝到开发板:

安装arm-linux-gdb

如果需要在开发版上在线调试的,需要安装开发板的arm-linux-gdbserver;如果只是开发一些简单的图形界面,个人觉得可以直接使用ubuntu的qtcreater,开发好后,拷贝到开发板即可,但是如果开发的qt需要在线调试开发版的硬件资源,则需要安装arm-gdb.
下载:http://ftp.gnu.org/gnu/gdb/

这里需要说明:gdb和gcc不是同一个项目,(记得g++和gcc也不是同一个项目)所以就有兼容问题例如:memcpy(p_str1, p_str2, sizeof(struct abc))函数在早期版本的gcc中,对语法检测不是很严格,sizeof返回值自动转为int,但是在新版本gcc中会报错,类型不匹配。我试过三个版本的gdb,结合我的gcc报错最少的是gdb-7.11.tar.gz
arm-linux-gdb和arm-linux-gdbserver需要分开编译,gdb是给qtcreate用的,是x86的;arm-linux-gdbserver是给板子用的,是arm的;所以gcc是不一样的。

解压

# tar xvf gdb-7.11.tar.gz -C ~/software

编译arm-linux-gdb

#./configure --target=arm-linux --prefix=/usr/local/arm-linux-gdb
#make
#make install

这里会编译错误,在make到example目录的时候显示找不到图形库,不过没有关系,主要东东已经ok,如果没有强迫证的话,可以掠过。

编译arm-linux-gdbserver

# cd ~/software/gdb-7.11/gdb/gdbserver
# ./configure  --target=arm-linux  --host=arm-linux
# make CC=arm-linux-gnueabi-gcc
# make install

这里可能会出现编译错误,很简单,结合自己的c语言基础+度娘,可以轻松搞定。

测试arm-linux-gdbserver

这个坑我不踩
当你非常兴奋的走到这里,终于可以看看gdbserver在板子中输出几行版本信息的时候,你可能得不到幸运之神的眷顾,居然报错了,怎么办?兵来将挡,水来土掩!
首先,在arm中使用file命令查看gdbserver格式,你会惊奇的看到:

root@beaglebone:/usr/local# file arm-linux-gdbserver 
arm-linux-gdbserver: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 2.6.32, BuildID[sha1]=7434d5d3bd2875dfc0f41d421e8a36d7eca2679a, not stripped

得到有用信息,

  1. elf是32位的arm,可以被板子执行。
  2. dynamically linked 需要/lib/ld-linux.so.3
    那么就好办了,看看/lib目录有没有这个so,发现没有。看过【程序员的自我修养】或熟悉编译原理的同学都知道ld是干嘛的,那么我直接将arm的ld创建一个同名软连接就ok了。
# ln -s /lib/arm-linux-gnueabihf/ld-2.19.so /lib/ld-linux.so.3

到此,大功告成!
收兵。

————————————————–

参考资料:
http://www.cnblogs.com/chenfulin5/p/5798764.html
http://www.cnblogs.com/cherishui/p/4414013.html

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.5</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>chainmaker.sdk</groupId> <artifactId>chain-maker-java-prod</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>java sdk Demo</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.chainmaker</groupId> <artifactId>chainmaker-sdk-java</artifactId> <version>2.3.1.3</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-tcnative-openssl-static</artifactId> <scope>system</scope> <version>2.0.39.Final</version> <systemPath>${project.basedir}/lib/netty-tcnative-openssl-static-2.0.39.Final.jar</systemPath> </dependency> <!-- java-sdk中的依赖 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> <version>2.11.1</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2.2</version> </dependency> <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcpkix-jdk15on</artifactId> <version>1.62</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.62</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java-util</artifactId> <version>3.2.0</version> <exclusions> <exclusion> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </exclusion> <exclusion> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-handler</artifactId> <version>4.1.53.Final</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-api</artifactId> <version>1.23.0</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty</artifactId> <version>1.23.0</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-stub</artifactId> <version>1.23.0</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-protobuf</artifactId> <version>1.23.0</version> </dependency> <!-- <dependency>--> <!-- <groupId>org.projectlombok</groupId>--> <!-- <artifactId>lombok</artifactId>--> <!-- <version>1.18.16</version>--> <!-- </dependency>--> <dependency> <groupId>org.web3j</groupId> <artifactId>abi</artifactId> <version>5.0.0</version> </dependency> <!-- <dependency>--> <!-- <groupId>mysql</groupId>--> <!-- <artifactId>mysql-connector-java</artifactId>--> <!-- <version>8.0.21</version>--> <!-- </dependency>--> <dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <version>5.6.0</version> </dependency> <!--spring boot--> <!-- <dependency>--> <!-- <groupId>ch.qos.logback</groupId>--> <!-- <artifactId>logback-classic</artifactId>--> <!-- <version>1.2.3</version>--> <!-- </dependency>--> <!--spring boot--> <!-- <dependency>--> <!-- <groupId>org.yaml</groupId>--> <!-- <artifactId>snakeyaml</artifactId>--> <!-- <version>1.29</version>--> <!-- </dependency>--> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- 打包时包含引入的外部jar包 --> <includeSystemScope>true</includeSystemScope> <classifier>exec</classifier> <mainClass>chainmaker.sdk.demo.DemoApplication</mainClass> </configuration> <version>2.2.2.RELEASE</version> </plugin> </plugins> </build> </project> 区块链的grpc版本太低,想要升级到1.44以上
最新发布
12-10
<think>我们有一个Spring Boot Maven项目,需要将gRPC相关依赖从1.23.0升级到1.44以上版本(如1.44.0或更高)。涉及的依赖包括:grpc-api、grpc-netty、grpc-stub、grpc-protobuf。 根据引用[1]中的经验,升级gRPC版本可能会遇到依赖冲突和兼容性问题,特别是与grpc-netty-shaded和guava包相关的问题。 步骤: 1. 修改Maven依赖版本:在pom.xml中,将gRPC相关依赖的版本号统一改为目标版本(如1.44.0)。注意,gRPC的各个模块版本应该保持一致。 2. 注意grpc-netty-shaded:在引用[1]中提到grpc-netty-shaded在1.22.2版本会导致问题。在1.44版本中,我们可能需要使用grpc-netty-shaded代替grpc-netty,因为grpc-netty-shaded是Netty的一个封装版本,可以避免与项目中其他Netty版本冲突。但也要注意其内部依赖。 3. 检查Guava版本:gRPC依赖Guava,而Guava在较新版本中移除了一些类。需要确保Guava版本与gRPC 1.44+兼容。根据gRPC官方文档,1.44版本可能需要Guava 30.0或更高版本(具体需查看官方说明)。 4. 可能还需要更新protobuf相关依赖:gRPC通常与protobuf一起使用,因此protobuf-java和protobuf-java-util的版本也需要与gRPC版本匹配。 具体操作: 1. 在pom.xml中,找到gRPC依赖,类似如下: ```xml <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-api</artifactId> <version>1.23.0</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty</artifactId> <version>1.23.0</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-stub</artifactId> <version>1.23.0</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-protobuf</artifactId> <version>1.23.0</version> </dependency> ``` 将版本号改为1.44.0(或更高,如1.44.1)。注意:所有gRPC依赖版本必须一致。 2. 考虑使用grpc-netty-shaded:为了避免Netty版本冲突,可以替换grpc-netty为grpc-netty-shaded: ```xml <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty-shaded</artifactId> <version>1.44.0</version> </dependency> ``` 同时移除grpc-netty依赖。 3. 检查并更新Guava依赖:查看gRPC 1.44.0的官方文档或Maven仓库,确定其依赖的Guava版本。然后确保项目中引入的Guava版本与之兼容。通常,gRPC 1.44.0需要Guava 30.1.0或更高版本。可以显式指定Guava版本: ```xml <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>31.0.1-jre</version> <!-- 使用与gRPC兼容的版本 --> </dependency> ``` 4. 更新protobuf依赖:如果使用了protobuf,需要更新protobuf-java等依赖。gRPC 1.44.0通常需要protobuf-java 3.12.0或更高版本。例如: ```xml <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>3.19.4</version> </dependency> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java-util</artifactId> <version>3.19.4</version> </dependency> ``` 5. 使用Maven命令清理并重新构建项目: ``` mvn clean install ``` 或通过IDE重新导入项目并构建。 6. 测试:启动项目并运行测试,确保没有兼容性问题。特别注意之前引用[1]中提到的grpc-netty-shaded和Guava的问题。 注意事项: - 如果项目中还有其他依赖间接引用了Netty或Guava,可能会发生版本冲突。可以使用Maven的依赖树命令来检查冲突: ``` mvn dependency:tree ``` 然后使用`<exclusion>`排除不需要的传递依赖。 - 如果升级后出现类找不到或方法不存在的问题,可能是由于gRPC版本升级后API发生了变化,需要检查代码并做相应调整。 引用[1]中提到的坑: 第一个坑:grpc-netty-shaded.jar导致启动报错。在1.44版本中,我们使用grpc-netty-shaded,但要注意它是否在类路径中正确加载,并且没有其他冲突。 第二个坑:Guava版本问题。确保使用兼容的Guava版本(如31.0.1-jre)。 综上,升级步骤主要是修改版本号,替换netty为netty-shaded,更新Guava和Protobuf版本,并解决可能的冲突。 如果升级过程中遇到问题,可以查看gRPC官方升级指南或GitHub issue。 参考引用[2][3]中关于gRPC的基本信息,升级后仍然保持其高性能和跨语言特性。 最后,根据引用[4]中的示例代码,升级后客户端和服务端的代码可能不需要改变,因为gRPC的API设计保持向后兼容,但也要注意官方是否有一些不兼容的变更。 因此,具体步骤总结为: 1. 统一升级gRPC依赖版本至1.44.0(或更高)。 2. 用grpc-netty-shaded替换grpc-netty。 3. 升级Guava至兼容版本(如31.0.1-jre)。 4. 升级Protobuf至兼容版本(如3.19.4)。 5. 解决其他依赖冲突。 6. 测试。 注意:以上版本号仅为示例,实际请参考gRPC官方发布的兼容性信息。 </think> ### 在Spring Boot Maven项目中升级gRPC依赖的方法 #### 步骤 1: 修改gRPC依赖版本 在`pom.xml`中统一升级所有gRPC相关依赖至目标版本(例如1.44.1): ```xml <!-- 更新所有gRPC依赖版本 --> <properties> <grpc.version>1.44.1</grpc.version> <!-- 以1.44.1为例 --> </properties> <dependencies> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-api</artifactId> <version>${grpc.version}</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty-shaded</artifactId> <!-- 推荐使用shaded版 --> <version>${grpc.version}</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-stub</artifactId> <version>${grpc.version}</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-protobuf</artifactId> <version>${grpc.version}</version> </dependency> </dependencies> ``` #### 步骤 2: 解决关键兼容性问题 1. **Netty依赖冲突** - 移除旧版`grpc-netty`,改用`grpc-netty-shaded`(已封装隔离依赖) - 检查并排除冲突的Netty传递依赖: ```xml <dependency> <groupId>some.dependency</groupId> <artifactId>conflict-artifact</artifactId> <exclusions> <exclusion> <groupId>io.netty</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> ``` 2. **Guava版本兼容** gRPC 1.44+需要Guava ≥30.1,显式声明版本: ```xml <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>31.1-jre</version> <!-- 兼容版本 --> </dependency> ``` #### 步骤 3: 更新Protobuf依赖 同步升级Protocol Buffers版本(需与gRPC兼容): ```xml <properties> <protobuf.version>3.19.4</protobuf.version> </properties> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>${protobuf.version}</version> </dependency> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java-util</artifactId> <version>${protobuf.version}</version> </dependency> ``` #### 步骤 4: 验证与测试 1. 执行依赖树检查: ```bash mvn dependency:tree -Dincludes=io.grpc,com.google.protobuf ``` 确保所有gRPC组件版本统一,无冲突传递依赖。 2. 启动测试时关注: - Netty的初始化日志(应显示`grpc-netty-shaded`) - Guava相关类缺失错误(需确保版本≥30.1) - Protobuf序列化异常(检查字段兼容性) #### 补充说明 - **gRPC 1.44+变化**:新版强化了HTTP/2特性,需确保客户端/服务端代码符合API规范[^2][^3] - **回滚策略**:建议分阶段升级,先升级测试环境验证稳定性 - **区块链集成**:若使用Fabric SDK等组件,需同步验证其gRPC兼容性 > **关键提示**:根据引用[1]的经验,`grpc-netty-shaded`和Guava版本是升级中最易出错的点,务必重点验证[^1]。升级后建议使用引用[4]的示例代码进行基础功能测试[^4]。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值