下载地址MSYS2
下载msys2-x86_64-20220603.exe
安装过程一直Next就可以。
我安装在(D:\msys64)
在自己工程同级目录下创建thirdparty文件夹,在thirdparty里创建librdkafka文件夹
将
D:\msys64\mingw64\bin\libcrypto-1_1-x64.dll
D:\msys64\mingw64\bin\libgcc_s_seh-1.dll
D:\msys64\mingw64\bin\liblz4.dll
D:\msys64\mingw64\bin\librdkafka.dll
D:\msys64\mingw64\bin\libssl-1_1-x64.dll
D:\msys64\mingw64\bin\libwinpthread-1.dll
D:\msys64\mingw64\bin\libzstd.dll
D:\msys64\mingw64\bin\zlib1.dll
D:\msys64\mingw64\include\librdkafka\rdkafkacpp.h
D:\msys64\mingw64\include\librdkafka\rdkafka_mock.h
D:\msys64\mingw64\lib\librdkafka++.dll.a
复制到创建好的librdkafka文件夹中,文件目录如下:
├─bin
│ libcrypto-1_1-x64.dll
│ libgcc_s_seh-1.dll
│ liblz4.dll
│ librdkafka++.dll
│ libssl-1_1-x64.dll
│ libwinpthread-1.dll
│ libzstd.dll
│ zlib1.dll
│
├─include
│ └─librdkafka
│ rdkafkacpp.h
│ rdkafka_mock.h
│
└─lib
librdkafka++.dll.a
然后打开QT工程的.pro文件,在里面添加刚才lib的路径和头文件的路径
DEFINES += LIBRDKAFKA_STATICLIB
win32 {
LIBS += ../thirdparty/librdkafka/lib/librdkafka++.dll.a
LIBS += -lws2_32 -lsecur32 -lcrypt32
}
INCLUDEPATH+=../thirdparty/librdkafka/include
点击运行会提示缺少dll文件,将\bin目录下的所有文件放到Release/Debug文件下,再次运行就OK了。