编译前工作
请安装arm交叉编译工具链,然后参考mosquitto之linux编译中CMake的使用方法,注意需要修改如下配置选项:
- CMAKE_AR,指定到交叉编译工具链中的
ar程序,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-ar。 - CMAKE_CXX_COMPILER,指定到交叉编译工具链中的
g++程序,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++。 - CMAKE_C_COMPILER,指定到交叉编译工具链中的
gcc程序,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc。 - CMAKE_INSTALL_OLDINCLUDEDIR,默认为
/usr/include。这里改为/opt/mosquitto-1.6.9-arm/include。 - CMAKE_INSTALL_PREFIX,指定mosquitio编译后的安装路径,默认为
/usr/local。这里改为/opt/mosquitto-1.6.9-arm。 - CMAKE_LINKER,指定到交叉编译工具链中的
ld程序,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-ld。 - CMAKE_NM,指定到交叉编译工具链中的
nm程序,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-nm。 - CMAKE_OBJCOPY,指定到交叉编译工具链中的
objcopy程序,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-objcopy。 - CMAKE_OBJDUMP,指定到交叉编译工具链中的
objdump程序,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-objdump。 - CMAKE_RANLIB,指定到交叉编译工具链中的
ranlib程序,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-ranlib。 - CMAKE_STRIP,指定到交叉编译工具链中的
strip程序,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-strip。 - LIBPTHREAD,指定到交叉编译工具链中的
libpthread.so库,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/lib/libpthread.so.0。 - LIBRT,指定到交叉编译工具链中的
librt.so库,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/lib/librt.so.1。 - OPENSSL_CRYPTO_LIBRARY,指定到交叉编译工具链中的
libcrypto.so库,若不使用OpenSSL则可以不设置,例如:/opt/openssl-1.1.1-arm/lib/libcrypto.so。 - OPENSSL_INCLUDE_DIR,指定到交叉编译工具链中的OpenSSL头文件目录,若不使用OpenSSL则可以不设置,例如:
/opt/openssl-1.1.1-arm/include。 - OPENSSL_SSL_LIBRARY,指定到交叉编译工具链中的
libssl.so库,若不使用OpenSSL则可以不设置,例如:/opt/openssl-1.1.1-arm/lib/libssl.so。 - PKG_CONFIG_EXECUTABLE,指定到交叉编译工具链中的
pkg_config程序,例如:/home/crosstool/sysroots/x86_64-oesdk-linux/usr/bin/pkg-config。 - WITH_STATIC_LIBRARIES,指定是否同时编译出静态库,若打勾则除了动态库还会编译出静态库,默认不打勾(只编译动态库)。
- WITH_TLS,指定是否包含SSL/TLS支持,默认打勾(若打勾,必须设置OpenSSL相关配置选项),若不想使用SSL,则不打勾。
- WITH_TLS_PSK,指定是否包含TLS_PSK支持,默认打勾(若打勾,必须同时把WITH_TLS打勾),若不想使用SSL,则不打勾。
编译源码
打开终端,输入命令:make,成功后,输入命令:make install,即可把mosquitto库安装到目录:/opt/mosquitto-1.6.9-arm。





