1. 下载
git clone https://github.com/eclipse/paho.mqtt.c
2. 编译
a. 在 cmake/ 下创建一个自己的 交叉编译链 cmake 文件 toolchain.linux-aaa.cmake
# path to compiler and utilities
# specify the cross compiler
SET(CMAKE_C_COMPILER aaa-gnu-gcc)
SET(CMAKE_CXX_COMPILER aaa-gnu-g++)SET(CMAKE_INSTALL_PREFIX /work/MQTT/paho.mqtt.c/build/output)# Name of the target platform
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR aaa)#openssl
SET(OPENSSL_ROOT_DIR /work/MQTT/openssl-1.1.1g-libs/Bin)
SET(OPENSSL_LIBRARIES /work/MQTT/openssl-1.1.1g-libs/Bin/lib)
SET(OPENSSL_INCLUDE_DIR /work/MQTT/openssl-1.1.1g-libs/Bin/include)# Version of the system
SET(CMAKE_SYSTEM_VERSION 1)
非交叉编译版本
# path to compiler and utilities
# specify the cross compiler
#SET(CMAKE_C_COMPILER aaa-gnu-gcc)
#SET(CMAKE_CXX_COMPILER aaa-gnu-g++)SET(CMAKE_INSTALL_PREFIX /work/MQTT/paho.mqtt.c/build-gcc/output)# Name of the target platform
#SET(CMAKE_SYSTEM_NAME Linux)
#SET(CMAKE_SYSTEM_PROCESSOR aaa)#openssl
SET(OPENSSL_ROOT_DIR /work/MQTT/openssl-1.1.1g-libs-gcc/Bin)
SET(OPENSSL_LIBRARIES /work/MQTT/openssl-1.1.1g-libs-gcc/Bin/lib)
SET(OPENSSL_INCLUDE_DIR /work/MQTT/openssl-1.1.1g-libs-gcc/Bin/include)# Version of the system
SET(CMAKE_SYSTEM_VERSION 1)
b.
$ mkdir build && cd build
$ cmake .. \
-DPAHO_WITH_SSL=TRUE \
-DPAHO_BUILD_SAMPLES=TRUE \
-DCMAKE_TOOLCHAIN_FILE=/work/MQTT/paho.mqtt.c/cmake/toolchain.linux-aaa.cmake
$ make -j8
$ make install
编译结果在 build/output 下了:
$ ll output/lib/
总用量 1104
drwxrwxr-x 3 4096 7月 16 15:52 ./
drwxrwxr-x 6 4096 7月 16 15:52 ../
drwxrwxr-x 3 4096 7月 16 15:52 cmake/
lrwxrwxrwx 1 19 7月 16 15:52 libpaho-mqtt3a.so -> libpaho-mqtt3a.so.1
lrwxrwxrwx 1 23 7月 16 15:52 libpaho-mqtt3a.so.1 -> libpaho-mqtt3a.so.1.3.9
-rw-r--r-- 1 277154 7月 16 15:52 libpaho-mqtt3a.so.1.3.9
lrwxrwxrwx 1 20 7月 16 15:52 libpaho-mqtt3as.so -> libpaho-mqtt3as.so.1
lrwxrwxrwx 1 24 7月 16 15:52 libpaho-mqtt3as.so.1 -> libpaho-mqtt3as.so.1.3.9
-rw-r--r-- 1 312241 7月 16 15:52 libpaho-mqtt3as.so.1.3.9
lrwxrwxrwx 1 19 7月 16 15:52 libpaho-mqtt3c.so -> libpaho-mqtt3c.so.1
lrwxrwxrwx 1 23 7月 16 15:52 libpaho-mqtt3c.so.1 -> libpaho-mqtt3c.so.1.3.9
-rw-r--r-- 1 244128 7月 16 15:52 libpaho-mqtt3c.so.1.3.9
lrwxrwxrwx 1 20 7月 16 15:52 libpaho-mqtt3cs.so -> libpaho-mqtt3cs.so.1
lrwxrwxrwx 1 24 7月 16 15:52 libpaho-mqtt3cs.so.1 -> libpaho-mqtt3cs.so.1.3.9
-rw-r--r-- 1 277527 7月 16 15:52 libpaho-mqtt3cs.so.1.3.9
c. 出错信息
没有安装 doxygen 时,cmake 后会报以下信息:
"Doxygen is needed to build the documentation."
安装 doxygen:
$ sudo apt-get install doxygen-latex doxygen-doc doxygen-gui graphviz