如何为ARM交叉编译Paho-MQTT-C库?

物联网 MQTT linux 帕霍
2021-06-18 13:12:03

如何为 ARM 平台交叉编译 Paho-MQTT C 库。

这是我遵循的步骤。

1) Downloaded library from [https://github.com/eclipse/paho.mqtt.embedded-c][here]
2) after download, I opened the directory and entered some commands.
3) command for setting the GCC-ARM tool chain (environment variable_path)
4) make CC=(ARM-CROSS_COMPILE)gcc

接下来,我观察到以下错误

mkdir -p build/output/samples
mkdir -p build/output/test
echo OSTYPE is Linux
OSTYPE is Linux
sed -e "s/@CLIENT_VERSION@/1.2.0/g" -e "s/@BUILD_TIMESTAMP@/Mon Apr 16 17:13:10 IST 2018/g" src/VersionInfo.h.in > build/VersionInfo.h
arm-cortexa9-linux-gnueabihf-gcc -g -fPIC  -Os -Wall -fvisibility=hidden -Ibuild -o build/output/libpaho-mqtt3c.so.1.0 src/MQTTPersistence.c src/Heap.c src/Socket.c src/MQTTProtocolClient.c src/MQTTProtocolOut.c src/StackTrace.c src/MQTTPersistenceDefault.c src/MQTTClient.c src/Messages.c src/MQTTPacketOut.c src/Clients.c src/OsWrapper.c src/Thread.c src/MQTTPacket.c src/Log.c src/LinkedList.c src/utf-8.c src/SocketBuffer.c src/Tree.c  -shared -Wl,-init,MQTTClient_init -lpthread -Wl,-soname,libpaho-mqtt3c.so.1
ln -s libpaho-mqtt3c.so.1.0  build/output/libpaho-mqtt3c.so.1
ln -s libpaho-mqtt3c.so.1 build/output/libpaho-mqtt3c.so
arm-cortexa9-linux-gnueabihf-gcc -g -fPIC  -Os -Wall -fvisibility=hidden -Ibuild -o build/output/libpaho-mqtt3cs.so.1.0 src/MQTTPersistence.c src/Heap.c src/Socket.c src/SSLSocket.c src/MQTTProtocolClient.c src/MQTTProtocolOut.c src/StackTrace.c src/MQTTPersistenceDefault.c src/MQTTClient.c src/Messages.c src/MQTTPacketOut.c src/Clients.c src/OsWrapper.c src/Thread.c src/MQTTPacket.c src/Log.c src/LinkedList.c src/utf-8.c src/SocketBuffer.c src/Tree.c -DOPENSSL  -shared -Wl,--start-group -lpthread -ldl -lssl -lcrypto -Wl,--end-group -Wl,-init,MQTTClient_init -Wl,-soname,libpaho-mqtt3cs.so.1 -Wl,-no-whole-archive
In file included from src/MQTTPersistence.h:23:0,
             from src/MQTTPersistence.c:28:
src/Clients.h:29:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
In file included from src/Socket.c:32:0:
src/SocketBuffer.h:28:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
In file included from src/SSLSocket.c:31:0:
src/SocketBuffer.h:28:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
In file included from src/MQTTPacket.h:25:0,
             from src/MQTTProtocolClient.h:25,
             from src/MQTTProtocolClient.c:34:
src/SSLSocket.h:29:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
In file included from src/MQTTPacket.h:25:0,
             from src/MQTTProtocolOut.h:24,
             from src/MQTTProtocolOut.c:35:
src/SSLSocket.h:29:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
In file included from src/StackTrace.c:21:0:
src/Clients.h:29:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
In file included from src/MQTTPersistence.h:23:0,
             from src/MQTTClient.c:53:
src/Clients.h:29:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
In file included from src/MQTTPacket.h:25:0,
             from src/MQTTPacketOut.h:22,
             from src/MQTTPacketOut.c:29:
src/SSLSocket.h:29:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
In file included from src/Clients.c:24:0:
src/Clients.h:29:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
In file included from src/MQTTPacket.h:25:0,
             from src/MQTTPacket.c:26:
src/SSLSocket.h:29:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
In file included from src/MQTTPacket.h:25:0,
             from src/Log.c:27:
src/SSLSocket.h:29:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
In file included from src/SocketBuffer.c:25:0:
src/SocketBuffer.h:28:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
Makefile:219: recipe for target 'build/output/libpaho-mqtt3cs.so.1.0' failed
make: *** [build/output/libpaho-mqtt3cs.so.1.0] Error 1

4)我使用这个命令安装了openssl

$ sudo apt-get install libssl-dev*

Openssl 安装成功,但仍然出现上述错误。

为 ARM 编译 Paho-MQTT-C 库需要做什么?

1个回答

您正面临这些构建错误,因为您缺少与用作 CC 的 arm-gcc 对应的 sysroot。

您可以尝试按如下方式更改 Makefile:

diff --git a/Makefile b/Makefile
index 49cbb13..1123f27 100755
--- a/Makefile
+++ b/Makefile
@@ -67,7 +67,7 @@ endif

 ifeq ($(OSTYPE),Linux)

-CC ?= gcc
+CC ?= /path/to/arm-linux-gnueabi/arm-linux-gnueabi-gcc-4.9.3

 ifndef INSTALL
 INSTALL = install
@@ -82,10 +82,10 @@ VERSION = ${MAJOR_VERSION}.${MINOR_VERSION}
 EMBED_MQTTLIB_C_TARGET = ${blddir}/lib${MQTT_EMBED_LIB_C}.so.${VERSION}


-CCFLAGS_SO = -g -fPIC -Os -Wall -fvisibility=hidden -DLINUX_SO
-FLAGS_EXE = -I ${srcdir}  -L ${blddir}
+CCFLAGS_SO = --sysroot=/path/to/sysroot -g -fPIC -Os -Wall -fvisibility=hidden -DLINUX_SO
+FLAGS_EXE = --sysroot=/path/to/sysroot -I ${srcdir}  -L ${blddir}

-LDFLAGS_C = -shared -Wl,-soname,lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION}
+LDFLAGS_C = --sysroot=/path/to/sysroot -shared -Wl,-soname,lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION}

 all: build

@@ -168,8 +168,8 @@ VERSION = ${MAJOR_VERSION}.${MINOR_VERSION}
 EMBED_MQTTLIB_C_TARGET = ${blddir}/lib${MQTT_EMBED_LIB_C}.so.${VERSION}


-CCFLAGS_SO = -g -fPIC -Os -Wall -fvisibility=hidden -Wno-deprecated-declarations -DUSE_NAMED_SEMAPHORES
-FLAGS_EXE = -I ${srcdir}  -L ${blddir}
+CCFLAGS_SO = --sysroot=/path/to/sysroot -g -fPIC -Os -Wall -fvisibility=hidden -Wno-deprecated-declarations -DUSE_NAMED_SEM
+FLAGS_EXE = --sysroot=/path/to/sysroot -I ${srcdir}  -L ${blddir}

 LDFLAGS_C = -shared -Wl,-install_name,lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION}

您将需要更改添加正确SYSROOT路径CCFLAGS_SOFLAGS_EXELDFLAGS_C在Makefile中的变量。我只举了例子。

当我进行这些替换时,我能够构建 paho。