1

How to for cross compiling Paho-MQTT C library for ARM platform.

Here are the steps I followed.

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

Next, I observe following error

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) I installed openssl using this command

$ sudo apt-get install libssl-dev*

Openssl installed successfully, but still getting the same above error .

What I have to do for compiling Paho-MQTT-C library for ARM?

3
  • 2
    Please do not cross post the same question to multiple Stack Exchange sites. (stackoverflow.com/questions/49898509/…) – hardillb Apr 19 '18 at 11:54
  • I'm voting to close this question as off-topic because it's a crosspost and the other question has already an answer. stackoverflow.com/questions/49898509 – Helmar Apr 20 '18 at 14:29
  • The errors are because you don't have SSL headers for your target - your apt-get attempt only installs them for building software for your build machine, but you need a set appropriate to building your target. In addition to the duplication, a major reason this needs to be closed is that "ARM" is not a target - what matters here is not the CPU family, but the target software environment, and that is entirely unspecified in your question. There are ARM parts playing Arduino roles and hiding inside SD cards, and there are ARM parts challenging Intel PCs. – Chris Stratton Apr 21 '18 at 17:29
3

You are facing these build errors as you are missing the sysroot corresponding to the arm-gcc that you are using as your CC.

You may try changing the Makefile as follows:

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}

You will need to change add the right sysroot path to CCFLAGS_SO, FLAGS_EXE and LDFLAGS_C variables in Makefile. I have only given examples.

When I made these substitutions I was able to build paho.

1
  • I need to compile the PAHO MQTT C++ library from my arm compiler. WIll you please help me to locate a MAKE file in paho.mqtt.cpp to adopt the above mentioned steps? – Mahamutha M Apr 11 '20 at 4:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.