基于Ubuntu20.04版本源码编译qtmqtt至loongarch平台

这段时间在2k1000la开发板上跑qt,尝试连接阿里云,踩了不少坑,记录一下。

使用的是loongNix系统,loongOS使用qt自带的qmake就可以跑。

一、搭建龙芯开发环境

1、下载loongarch的交叉编译链 龙芯开源社区 (loongnix.cn)

2、将其添加进环境变量,我在/etc/profile中存放

3、使用source命令使这个环境变量生效

3、在命令行输入loong ,使用tab键出现各种gcc交叉编译链时,就说明环境变量设置成功

二、搭建qt环境

1、下载qt源码,Index of /archive/qt/5.15/5.15.2/single

2、将其通过MobaXterm工具(filezilla也可以)传输到ubuntu下

3、将其解压至一个目录下。

4、打开,进入qt-everywhere-src-5.15.2/qtbase/mkspecs/ ,在这个目录下有各种目标架构的交叉编译工具,由于loongarch没有支持,所以需要自己修改,操作如下:复制linux-aarch64-gnu-g++目录另存为linux-loongarch-gnu-g++,进入linux-loongarch-gnu-g++目录,修改qmake.conf文件,我习惯使用vscode,直接用vscode打开,修改之前:

修改之后:

5、在qt源码解压目录下,新建脚本文件autoconfig.sh,使用vscode打开,插入如下代码,第一行是我最终要输出的目录,第7行是之前新建的目录名,一定要对应起来,否则会报错,找不到目标架构,这里没有添加tslib,需要的话使用-I -L将路径添加进去

./configure -prefix /home/duan/linux/tool/qt-everywhere-src-5.15.2/loongarch-qt \
-opensource \
-confirm-license \
-release \
-strip \
-shared \
-xplatform linux-loongarch-gnu-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 \
--libpng=qt \
--libjpeg=qt \
--sqlite=qt \
-plugin-sql-sqlite \
-recheck-all

 6、使用chmod将autoconfig.sh文件设置为可执行文件,并运行,运行时报错

 解决:在所有的报错文件中加入#include <limits>

7、再次编译报错:

龙芯是全新的指令集,即qt源码对龙芯没有宏定义,解决:

修改/qt-everywhere-src-5.15.2/qtbase/src/3rdparty/double-conversion/include/double-conversion目录下的utils.h文件里面的宏定义

 8、编译,再次报错:

 这个错是高版本的ubuntu的问题,我看了网上的资料,说是16.0可以,别的不行,猜测是GCC版本过高,解决:降低GCC版本

操作:

(1)使用管理员权限复制/etc/apt/source.list 为source.list.old

(2)删除source.list里面的内容,将gcc -5需要的软件源添加进source.list

内容如下:

deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main
 
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main
 
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
 
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe

 (3)完成后更新一下软件源,再使用 sudo apt-get install gcc-5 g++-5 -y命令下载gcc5.4版本

   (4)执行以下命令,将高版本的gcc切换为低版本的gcc

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 1

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 1

(5)查看 gcc -v

已经变成了与ubuntu16.0一致的版本gcc5.4

9、再一次编译,报错make[7]: 进入目录“/home/duan/linux/tool/qt-everywhere-src-5.15.2/qtdeclarative/examples/qml/tutorials/extending-qml/chapter6-plugins/import” make[7]: *** 没有规则可制作目标“plugins.qmltypes”,由“../Charts/plugins.qmltypes” 需求。 停止。 make[7]: 离开目录“/home/duan/linux/tool/qt-everywhere-src-5.15.2/qtdeclarative/examples/qml/tutorials/extending-qml/chapter6-plugins/import” make[6]: *** [Makefile:48sub-import-make_first-ordered] 错误 2 make[6]: 离开目录“/home/duan/linux/tool/qt-everywhere-src-5.15.2/qtdeclarative/examples/qml/tutorials/extending-qml/chapter6-plugins” make[5]: *** [Makefile:177sub-chapter6-plugins-make_first] 错误 2 make[5]: 离开目录“/home/duan/linux/tool/qt-everywhere-src-5.15.2/qtdeclarative/examples/qml/tutorials/extending-qml” make[4]: *** [Makefile:47sub-extending-qml-make_first] 错误 2 make[4]: 离开目录“/home/duan/linux/tool/qt-everywhere-src-5.15.2/qtdeclarative/examples/qml/tutorials” make[3]: *** [Makefile:152sub-tutorials-make_first] 错误 2 make[3]: 离开目录“/home/duan/linux/tool/qt-everywhere-src-5.15.2/qtdeclarative/examples/qml” make[2]: *** [Makefile:74sub-qml-make_first] 错误 2 make[2]: 离开目录“/home/duan/linux/tool/qt-everywhere-src-5.15.2/qtdeclarative/examples” make[1]: *** [Makefile:101sub-examples-make_first] 错误 2 make[1]: 离开目录“/home/duan/linux/tool/qt-everywhere-src-5.15.2/qtdeclarative” make: *** [Makefile:163module-qtdeclarative-make_first] 错误 2

不知道什么原因,解决:删除现有的qt源码,重新解压配置,错误消失,编译完成之后就可以使用make install命令进行安装

10、安装完成后,就会我指定的源码路径下出现一个叫loongarch-qt的目录,进入/loongarch-qt/lib,里面就有支持loongarch架构的qmake工具。

三、编译mqtt

1、下载mqtt源码GitHub - qt/qtmqtt at 5.15.2

2、我将其解压在Download目录下,进入/Downloads/qtmqtt-5.15.2/src/mqtt/,将该目录下所有的头文件复制到loongarch-qt/include/QtMqtt目录下,这个QtMqtt目录是自己新建的,

进入新建的QtMqtt目录,新建文件 QMqttClient,打开文件添加#include "qmqttclient.h"

新建文件 QMqttSubscription,打开文件添加#include “qmqttsubscription.h”

新建文件 QMqttMessage,打开文件添加#include "qmqttmessage.h"

新建文件 QMqttTopicName,打开文件添加#include " qmqtttopicname.h "

3、回到mqtt源码路径,指定loongarch-qt/lib/qmake ,会出现一个Makefile文件

4、执行qmake,完成后,loongarch架构下mqtt所需要的动态链接库就会编译在/Downloads/qtmqtt-5.15.2/lib/目录下。

5、打开qt creator,在.pro文件下添加network模块,然后使用添加外部库,将刚才生成的.so文件及其路径添加进.pro文件,就可以使用mqtt库了

四,移植至2k1000la开发板

1、保证开发板与PC在同一网段,使用scp命令传输,关于在2k1000la开发板上找不到可执行文件的问题:

原因:缺少动态链接库 /lib/ld.so.1

解决:复制lib64文件夹里面的ld.so.1到/lib/文件夹下,不能进行软链接,会发生软链接嵌套错误。

2、运行该程序,缺少各种.so文件

遇到这种问题,使用ldd命令或者file命令查看执行该执行文件需要链接什么库,然后想办法找到这种库,但一定要loongarch支持的链接库,在运行可执行文件之前,需要接上屏幕,否则也会报错。

若有错误,望指正!

  • 34
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值