mosquitto库(MQTT)移植到ARM
MQTT(消息队列遥测传输)是ISO 标准(ISO/IEC PRF 20922)下基于发布/订阅范式的消息协议。它工作在 TCP/IP协议族上,是为硬件性能低下的远程设备以及网络状况糟糕的情况下而设计的发布/订阅型消息协议,为此,它需要一个消息中间件 。
MQTT是一个基于客户端-服务器的消息发布/订阅传输协议。MQTT协议是轻量、简单、开放和易于实现的,这些特点使它适用范围非常广泛。在很多情况下,包括受限的环境中,如:机器与机器(M2M)通信和物联网(IoT)。其在,通过卫星链路通信传感器、偶尔拨号的医疗设备、智能家居、及一些小型化设备中已广泛使用。
移植mosquitto动态库开始:
1.在将三个文件放入ubuntu16.04中并解压后,先移植openssl库
进入openssl库解压后的文件夹openssl-1.1.1g
执行命令配置(xxx为实际的交叉工具链路径、输出的移植文件)
CC=xxx/xxx/arm-linux-gcc ./config no-asm shared --prefix=xxx/xxx/openssl-1.1.1g-arm openssldir=xxx/xxx/openssl-1.1.1g-arm/ssl --host=arm-linux
或者
AR="arm-linux-gnueabi-ar" RANLIB=arm-linux-gnueabi-ranlib CC=arm-linux-gnueabi-gcc /usr/bin/perl ./configure shared linux-armv4 --prefix=XXX/XXX/openssl-arm
make -j8 (8核编译)
make install
2.移植uuid库,同样进入libuuid-1.0.3目录,执行以下命令:
./configure --prefix=xxx/xxx/libuuid-1.0.3-arm CC=xxx/xxx/arm-linux-gcc --host=arm-linux
make -j8
make install
3.移植Mosquitto库,进入目录:
make WITH_SRVSRV=no CC=xxx/xxx/arm-linux-gcc CXX=xxx/xxx/arm-linux-gnueabihf-g++ CFLAGS="-I xxx/xxx/openssl-1.1.1g-arm/include -I xxx/xxx/libuuid-1.0.3-arm/include -Ixxx/xxx/openssl-1.1.1g-arm/lib -Ixxx/xxx/libuuid-1.0.3-arm/lib" LDFLAGS="-L xxx/xxx/openssl-1.1.1g-arm/lib -Lxxx/xxx/libuuid-1.0.3-arm/lib -lssl -lcrypto -luuid"
make DESTDIR=xxx/xxx/mosquitto1.6.9-arm install
至此,所有库移植完成。
将libuuid-1.0.3-arm、openssl-1.1.1g-arm、mosquitto1.6.9-arm文件夹复制到工程中,就可以使用了。libuuid-1.0.3-arm、openssl-1.1.1g-arm中包含有静态库与动态库,但mosquitto1.6.9-arm中只有动态库。
移植mosquitto1.6.9静态库以后再研究,先用着。
当工具链不会自动找到包含路径时,移植这些库比较麻烦,需要自己加
LDFLAGS
CFLAGS
CXXFLAGS
例如:编译mosquitto可以这样
make WITH_SRVSRV=no CC=arm-oe-linux-gnueabi-gcc CXX=arm-oe-linux-gnueabi-g++ CFLAGS="-I XXXX/openssourcelib/openssl_install/include -I XXXX/openssourcelib/uuid_install/include -IXXXX/openssourcelib/openssl_install/lib -IXXXX/openssourcelib/uuid_install/lib -Wall -Wundef -finline-functions -finline-limit=64 -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard --sysroot=XXXX/ -I. -IXXXX/include -IXXXX/usr/include -IXXXX/usr/include/ql_lib_utils -IXXXX/usr/include/ql-sdk -Wall -Wundef -finline-functions -finline-limit=64" LDFLAGS="-march=armv7-a -marm -mfpu=neon -mfloat-abi=hard --sysroot=XXXX/ -L. -LXXXX/usr -LXXXX/usr/lib -L XXXX/openssourcelib/openssl_install/lib -LXXXX/openssourcelib/uuid_install/lib -lssl -lcrypto -luuid -lql_sdk -lpthread" CXXFLAGS="-I XXXX/openssourcelib/openssl_install/include -I XXXX/openssourcelib/uuid_install/include -IXXXX/openssourcelib/openssl_install/lib -IXXXX/openssourcelib/uuid_install/lib -Wall -Wundef -finline-functions -finline-limit=64 -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard --sysroot=XXXX/ -I. -IXXXX/include -IXXXX/usr/include -IXXXX/usr/include/ql_lib_utils -IXXXX/usr/include/ql-sdk -Wall -Wundef -finline-functions -finline-limit=64" WITH_CJSON=no
make DESTDIR=xxx/xxx/mosquitto1.6.9-arm WITH_SRVSRV=no CC=arm-oe-linux-gnueabi-gcc CXX=arm-oe-linux-gnueabi-g++ CFLAGS="-I XXXX/openssourcelib/openssl_install/include -I XXXX/openssourcelib/uuid_install/include -IXXXX/openssourcelib/openssl_install/lib -IXXXX/openssourcelib/uuid_install/lib -Wall -Wundef -finline-functions -finline-limit=64 -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard --sysroot=XXXX/ -I. -IXXXX/include -IXXXX/usr/include -IXXXX/usr/include/ql_lib_utils -IXXXX/usr/include/ql-sdk -Wall -Wundef -finline-functions -finline-limit=64" LDFLAGS="-march=armv7-a -marm -mfpu=neon -mfloat-abi=hard --sysroot=XXXX/ -L. -LXXXX/usr -LXXXX/usr/lib -L XXXX/openssourcelib/openssl_install/lib -LXXXX/openssourcelib/uuid_install/lib -lssl -lcrypto -luuid -lql_sdk -lpthread" CXXFLAGS="-I XXXX/openssourcelib/openssl_install/include -I XXXX/openssourcelib/uuid_install/include -IXXXX/openssourcelib/openssl_install/lib -IXXXX/openssourcelib/uuid_install/lib -Wall -Wundef -finline-functions -finline-limit=64 -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard --sysroot=XXXX/ -I. -IXXXX/include -IXXXX/usr/include -IXXXX/usr/include/ql_lib_utils -IXXXX/usr/include/ql-sdk -Wall -Wundef -finline-functions -finline-limit=64" WITH_CJSON=no install
编译libuuid可以这样
./configure --prefix=XXXXX/openssourcelib/uuid_install CC=XXXXX/arm-oe-linux-gnueabi-gcc CFLAGS="-march=armv7-a -marm -mfpu=neon -mfloat-abi=hard --sysroot=XXXXX -I. -IXXXXX/include -IXXXXX/usr/include -IXXXXX/usr/include/ql_lib_utils -IXXXXX/usr/include/ -Werror -Wall -Wundef -finline-functions -finline-limit=64" LDFLAGS="-march=armv7-a -marm -mfpu=neon -mfloat-abi=hard --sysroot=XXXXX -L. -LXXXXX/usr -LXXXXX/usr/lib -lpthread" --host=arm-oe-linux-gnueabi
x86上移植类似。(libcurl移植也是类似,设置--prefix选项就可以)
编译时出现fatal error: cjson/cJSON.h: No such file or directory
sudo apt install libcjson1 libcjson-dev
或者移植源码
https://sourceforge.net/projects/cjson/files/latest/download
https://github.com/DaveGamble/cJSON