ubuntu cross compile transplant paho.mqtt.c-1.3.0 to i.max6ull

This project is to transplant the mqtt protocol on i.mx6u

Record the problems and solutions when transplanting the mqtt protocol:

First of all, there is a problem when compiling MQTT according to the tutorial of punctual atoms. The reason is that there is a problem with the Makefile, and there is a problem with the openssl library when cross-compiling.

1. Download and cross-compile openssl

1.1 Download openssl

openssl official website

https://www.openssl.org/source/

Create a new folder openssl_arm to save the source code, and create an installation directory ssl_arm under this folder path

1.2 Configure source files to generate Makefile

sudo ./config no-async no-asm shared --prefix=/home/yzj/tools/openssl_arm/ssl_arm --cross-compile-prefix=arm-linux-gnueabihf-

Change the path in the command to your own path

After successful execution, a Makefile will be created in the directory

1.3 Modify Makefile

Enter openssl-1.1.1s, modify the makefile in this directory

It can be opened with the vim command, here I directly use vscode to open it for easy modification

1. Delete -m64 in the Makefile

In vscode, Ctrl + F searches for -m64 and deletes it. In some versions of the makefile, you need to check whether the compiler is arm-linux-gnueabihf- If not, you need to modify it one by one, such as gcc, ar, g++, etc.

2. Compile and generate related libraries

make & amp; & amp; make install

After compiling and installing, the ssl_arm directory is as follows, that is, the openssl cross-compilation is completed

2. Cross compilation and transplantation paho. mqttd

1.1 Download paho.mqtt.c-1.3.0 source code

Paho mqtt official website address: https://github.com/eclipse/paho.mqtt.c/releases

I downloaded version 1.3.0, please check the situation yourself and try to be consistent with me.

1.2 Modify Makefile

1. After downloading and decompressing, create the following folders under the paho.mqtt.c-1.3.0 folder

2. After the creation is complete, modify the Makefile as follows

Modify to specify the path build/install/local

3. Specify the cross-compilation toolchain

CC=/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc

4. Add ssl library path

CCFLAGS_SO + = -I /home/yzj/tools/openssl_arm/ssl_arm/include
LDFLAGS_C += -L /home/yzj/tools/openssl_arm/ssl_arm/lib
LDFLAGS_CS += -L /home/yzj/tools/openssl_arm/ssl_arm/lib
LDFLAGS_A += -L /home/yzj/tools/openssl_arm/ssl_arm/lib
LDFLAGS_AS += -L /home/yzj/tools/openssl_arm/ssl_arm/lib
FLAGS_EXE += -L /home/yzj/tools/openssl_arm/ssl_arm/lib
FLAGS_EXES += -L /home/yzj/tools/openssl_arm/ssl_arm/lib

Note: The path needs to be modified according to your own path

Above is my path.

5. Modify install and uninstall

install:

install: build
mkdir -p $(DESTDIR)$(PREFIX)${includedir}
mkdir -p $(DESTDIR)$(PREFIX)${libdir}
mkdir -p $(DESTDIR)$(PREFIX)${bindir}
mkdir -p $(DESTDIR)${man1dir}
mkdir -p $(DESTDIR)${man3dir}
cp -f ${MQTTLIB_C_TARGET} $(DESTDIR)${libdir}
cp -f ${MQTTLIB_CS_TARGET} $(DESTDIR)${libdir}
cp -f ${MQTTLIB_A_TARGET} $(DESTDIR)${libdir}
cp -f ${MQTTLIB_AS_TARGET} $(DESTDIR)${libdir}
cp -f ${MQTTVERSION_TARGET} $(DESTDIR)${bindir}
cp -f ${PAHO_C_PUB_TARGET} $(DESTDIR)${bindir}
cp -f ${PAHO_C_SUB_TARGET} $(DESTDIR)${bindir}
cp -f ${PAHO_CS_PUB_TARGET} $(DESTDIR)${bindir}
cp -f ${PAHO_CS_SUB_TARGET} $(DESTDIR)${bindir}
ln -sf lib$(MQTTLIBC).so.${MAJOR_VERSION} $(DESTDIR)${libdir}/lib$(MQTTLIB_C).so
ln -sf lib$(MQTTLIB_CS).so.${MAJOR_VERSION} $(DESTDIR)${libdir}/lib$(MQTTLIB_CS).so
ln -sf lib$(MQTTLIB_A).so.${MAJOR_VERSION} $(DESTDIR)${libdir}/lib$(MQTTLIB_A).so
ln -sf lib$(MQTTLIB_AS).so.${MAJOR_VERSION} $(DESTDIR)${libdir}/lib$(MQTTLIB_AS).so
ln -sf lib$(MQTTLIB_C).so.${VERSION} $(DESTDIR)${libdir}/lib$(MQTTLIB_C).so.${MAJOR_VERSION}

ln -sf lib$(MQTTLIB_CS).so.${VERSION} $(DESTDIR)${libdir}/lib$(MQTTLIB_CS).so.${MAJOR_VERSION}

ln -sf lib$(MQTTLIB_A).so.${VERSION} $(DESTDIR)${libdir}/lib$(MQTTLIB_A).so.${MAJOR_VERSION}

ln -sf lib$(MQTTLIB_AS).so.${VERSION} $(DESTDIR)${libdir}/lib$(MQTTLIB_AS).so.${MAJOR_VERSION}

cp -f ${srcdir}/MQTTAsync.h $(DESTDIR)${includedir}
cp -f ${srcdir}/MQTTClient.h $(DESTDIR)${includedir}
cp -f ${srcdir}/MQTTClientPersistence.h $(DESTDIR)${includedir}
cp -f ${srcdir}/MQTTProperties.h $(DESTDIR)${includedir}
cp -f ${srcdir}/MQTTReasonCodes.h $(DESTDIR)${includedir}
cp -f ${srcdir}/MQTTSubscribeOpts.h $(DESTDIR)${includedir}
- cp -f doc/man/man1/paho_c_pub.1 $(DESTDIR)${man1dir}
- cp -f doc/man/man1/paho_c_sub.1 $(DESTDIR)${man1dir}
- cp -f doc/man/man1/paho_cs_pub.1 $(DESTDIR)${man1dir}
- cp -f doc/man/man1/paho_cs_sub.1 $(DESTDIR)${man1dir}
- cp -f ${blddir}/doc/MQTTClient/man/man3/MQTTClient.h.3 $(DESTDIR)${man3dir}
- cp -f ${blddir}/doc/MQTTAsync/man/man3/MQTTAsync.h.3 $(DESTDIR)${man3dir}
@echo ""
@echo “make install finish”, 'date'
@echo ""

uninstall:

uninstall:
rm -rf $(blddir_work)
@echo ""
@echo “make uninstall finish”, 'date'
@echo ""

1.3 Compile

After the modification, make & amp; & amp; make install to generate the library

Here comes the point, if the following error occurs after executing the above command:

Check the build path and find that the doc folder is not generated. You need to run make html to generate it. When running make html, an error is reported /bin/sh: 1: doxygen: not found, and doxygen is not installed. Refer to this article: https://blog .csdn.net/yamida/article/details/79428515

After the installation is complete: sudo make uninstall to remove the wrong installation before, then make html, after no error is reported, then sudo make install to reinstall. as follows:

The next step is to package and transplant the i.max6ull. In general, I still encounter various problems, but it takes a little time to solve them.

Reference: http://e.betheme.net/zz/822260.aspx?action=onClick