Windows系统下使用MinGW编译paho.mqtt.c
1. 编译openssl
openssl-1.1.1k.tar.gz
下载地址
1.1 编译需要使用MSYS2环境
./config
make
1.2 配置环境变量
OPENSSL_CONF = “E:\3rd\openssl-1.1.1k\apps\openssl.cnf”
OPENSSL_ROOT_DIR = “E:\3rd\openssl-1.1.1k”
2. 编译paho.mqtt.c
2.1 需要配置的环境变量
LIBRARY_PATH = “D:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib”
C_INCLUDE_PATH = “D:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\include”
2.2 他用cmake-gui创建cmake
勾选 PAHO_WITH_SSL
需要编译静态库可勾选 PATO_BUILD_STATIC
去掉勾选 PAHO_ENABLE_TESTING win32下不支持编译不过
成功Generate
后
2.3 编译
2.4 修复一个错误
src/MQTTVersion.c
static const char* libraries[] = {"libpaho-mqtt3c", "libpaho-mqtt3cs", "libpaho-mqtt3a", "libpaho-mqtt3as"};
build> dir src
2021/05/12 17:54 <DIR> .
2021/05/12 17:54 <DIR> ..
2021/05/12 17:53 <DIR> CMakeFiles
2021/05/12 16:57 8,567 cmake_install.cmake
2021/05/12 16:31 2,809 eclipse-paho-mqtt-cConfigVersion.cmake
2021/05/12 15:35 3,687,951 libcrypto-1_1-x64.dll
2021/05/12 17:54 295,516 libpaho-mqtt3a-static.a
2021/05/12 17:54 273,730 libpaho-mqtt3a.dll
2021/05/12 17:54 34,684 libpaho-mqtt3a.dll.a
2021/05/12 17:54 327,106 libpaho-mqtt3as-static.a
2021/05/12 17:54 306,335 libpaho-mqtt3as.dll
2021/05/12 17:54 34,688 libpaho-mqtt3as.dll.a
2021/05/12 17:54 252,532 libpaho-mqtt3c-static.a
2021/05/12 17:54 240,951 libpaho-mqtt3c.dll
2021/05/12 17:54 36,530 libpaho-mqtt3c.dll.a
2021/05/12 17:54 284,838 libpaho-mqtt3cs-static.a
2021/05/12 17:54 273,895 libpaho-mqtt3cs.dll
2021/05/12 17:54 36,534 libpaho-mqtt3cs.dll.a
2021/05/12 15:35 926,355 libssl-1_1-x64.dll
2021/05/12 17:43 85,486 Makefile
2021/05/12 17:54 59,144 MQTTVersion.exe
>src\MQTTVersion.exe
MQTTVersion: print the version strings of an MQTT client library
Copyright (c) 2012, 2018 IBM Corp.
Specify a particular library name if it is not in the current directory, or not
executable on this platform
--- Trying library libpaho-mqtt3c ---
Product name: Eclipse Paho Synchronous MQTT C Client Library
Version: 1.3.8
Build level: 2021-05-12T09:53:27Z
--- Trying library libpaho-mqtt3cs ---
Product name: Eclipse Paho Synchronous MQTT C Client Library
Version: 1.3.8
Build level: 2021-05-12T09:53:27Z
OpenSSL version: OpenSSL 1.1.1k 25 Mar 2021
OpenSSL flags: compiler: gcc -m64 -Wall -O3 -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_C
PUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPEN
SSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM
-DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -D
POLY1305_ASM -DUNICODE -D_UNICODE -DWIN32_LEAN_AND_MEAN -D_MT -DNDEBUG
OpenSSL build timestamp: built on: Wed May 12 07:30:54 2021 UTC
OpenSSL platform: platform: mingw64
OpenSSL directory: OPENSSLDIR: "C:/Program Files/Common Files/SSL"
--- Trying library libpaho-mqtt3a ---
Product name: Eclipse Paho Asynchronous MQTT C Client Library
Version: 1.3.8
Build level: 2021-05-12T09:53:27Z
--- Trying library libpaho-mqtt3as ---
Product name: Eclipse Paho Asynchronous MQTT C Client Library
Version: 1.3.8
Build level: 2021-05-12T09:53:27Z
OpenSSL version: OpenSSL 1.1.1k 25 Mar 2021
OpenSSL flags: compiler: gcc -m64 -Wall -O3 -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_C
PUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPEN
SSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM
-DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -D
POLY1305_ASM -DUNICODE -D_UNICODE -DWIN32_LEAN_AND_MEAN -D_MT -DNDEBUG
OpenSSL build timestamp: built on: Wed May 12 07:30:54 2021 UTC
OpenSSL platform: platform: mingw64
OpenSSL directory: OPENSSLDIR: "C:/Program Files/Common Files/SSL"