MQTT交叉编译

忘记从哪里复制过来的了。。。。。

现在我要在 DM368 的交叉编译器 arm-none-linux-gnueabi-gcc 链接共享库 libmosquitto.so.1。出现问题 cannot find -lmosquitto 即共享库找不到。

然后我想可能是编译器不匹配 ,然后想用 DM368的交叉编译器arm-none-linux-gnueabi-gcc 再安装一遍 mqtt 服务器让其生成 共享库 libmosquitto.so.1,然后就make出现了一堆的错误。

这上面是我在群里发帖咨询的遇到的问题,现在最终成功解决!!

现在就讲一下是怎么操作的。

一、准备工作
上面说的编译不同造成的无法链接共享库这个是真的,需要重新 make 生成 libmosquitto.so.1。
我们现在的虚拟机上有安装交叉编译器 arm-none-linux-gnueabi-gcc 需要查看一下它所在的位置。

which arm-none-linux-gnueabi-gcc

/opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc
然后下载需要的软件
主要是两个 mosquitto-1.4.14 和 openssl-1.0.1c
下载:openssl-1.0.1c
下载:mosquitto-1.4.14
二、MQTT源码交叉编译
参看:mosquitto-1.4.9在Linux上的编译
(1)编译需要依赖的openssl
将上面下载的文件 openssl-1.0.1c.tar.gz 解压
tar -zxvf openssl-1.0.1c.tar.gz
然后进入该文件
cd openssl-1.0.1c
然后执行:
./config no-asm shared --prefix=/opt/com/ssl
注意 : /opt/com/ssl/ 文件夹是指定存放共享库的位置,你自己要先创建好的哦
然后修改Makefile中下列变量的值:
CC = /opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc
AR = /opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-ar $(ARFLAGS) r
RANLIB = /opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-ranlib
注意: 这里就是为什么上面要你查看交叉编译所在位置的原因了。
再有啊,记得需要将之前的变量值注释掉的哦。我第一次就忘记了,然后再编译的时候出现错误:
Relocations in generic ELF (EM: 3) libcrypto.a(e_old.o): could not read symbols: File in wrong format
解决方法,就是执行: #make clean -w

最后就是执行编译:

make && make install

(2)编译mosquitto-1.4.14客户端
将上面下载的文件 mosquitto-1.4.14.tar.gz 解压

tar -zxvf mosquitto-1.4.14.tar.gz

然后进入该文件
cd mosquitto-1.4.14
修改config.mk
WITH_SRV:=no
WITH_UUID:=no
WITH_WEBSOCKETS:=no
WITH_DOCS:=no
CFLAGS += -I/opt/com/ssl/include
LDFLAGS += -L/opt/com/ssl/lib -lssl -lcrypto
STRIP?=arm-none-linux-gnueabi-strip
注意: /opt/com/ssl/ 上面说了是共享库文件所在位置,你自己创建的。不过现在里面是有东西的。

执行编译
make CC=/opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc CXX=/opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-g++
最后执行
make install
最终在 /usr/locat/lib 目录下可以看到新生成的 libmosquitto.so.1

注意: 如果不修改 STRIP?=arm-none-linux-gnueabi-strip
会出现错误:strip: Unable to recognise the format of the input file `/usr/local/lib/libmosquitto.so.1’
这是参考那篇文章里所没有提到的。
三、总结
最后想不想看一下,gcc 和 arm-none-linux-gnueabi-gcc 编译生成的 libmosquitto.so.1 到底有啥不同。
gcc编译:

file libmosquitto.so.1

libmosquitto.so.1: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked,
BuildID[sha1]=0xb05795243eded68d65abe39b12212099c849965b, not stripped
arm-none-linux-gnueabi-gcc 交叉编译:

file libmosquitto.so.1

libmosquitto.so.1: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked,
not stripped
看出来了么? 是类型啦,主要是在 Intel 80386 执行还是在 ARM 执行的。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值