天天看点

mosquitto在windows10中VS2019进行编译出lib和dll

mosquitto在Windows编译需要环境如下:

1、cmake,安装Windows版的cmake。

2、VS2019安装;

3、openssl安装;

4、mosquitto源码;

5、windows版的pthread下载库。

其中的cmake和vs2019的安装可以百度自行安装。我们主要讲openssl安装、mosquitto编译、和调用windows版的phtread库

一、mosquitto源码下载和其他文件准备

1、编译详细过程可访问github说明。

mosquitto项目地址:https://github.com/eclipse/mosquitto

官网下载源码:https://mosquitto.org/download/

mosquitto在windows10中VS2019进行编译出lib和dll

 2、源码下载后就解压,如下图所示:

mosquitto在windows10中VS2019进行编译出lib和dll

3、openssl安装,下面是下载地址

http://slproweb.com/products/Win32OpenSSL.html

进入到openssl下载页面后选择64位版本下载

mosquitto在windows10中VS2019进行编译出lib和dll

 下载后是如下图一个exe,点击安装到默认路径就可以了

mosquitto在windows10中VS2019进行编译出lib和dll

4、windows上pthread库下载,从百度云盘上下载,其他csdn比较麻烦

链接: https://pan.baidu.com/s/189wW3u81esDd2qber9gGkg 提取码: pjsf 

二、对mosquitto进行编译

 1.打开cmake的cmake-gui应用,选择解压的mosquitto-master文件,创建新文件mosquitto-vs保存vs2019的工程文件

mosquitto在windows10中VS2019进行编译出lib和dll

 2、安装下面图片步骤生成vs工程文件

mosquitto在windows10中VS2019进行编译出lib和dll

 3、打开vs2019后需要把pthread添加到工程中编译,使用动态载入的方式使得程序必须依赖其dll,如果dll丢失,将导致程序无法运行。

在libmosquitto点击右键选择属性

mosquitto在windows10中VS2019进行编译出lib和dll

 以Release—X64环境为例

4.选择链接器->常规->附加库目录输入

pthread\lib\v110\x64\Release\static\cdecl

mosquitto在windows10中VS2019进行编译出lib和dll

 5、选择链接器->输入->附加依赖项输入

libpthread-static.lib

mosquitto在windows10中VS2019进行编译出lib和dll

 6.选择C/C++ ->常规->附加包含目录输入

pthread\include

mosquitto在windows10中VS2019进行编译出lib和dll

7.选择C/C++ ->预处理器->预处理器定义输入

PTW32_STATIC_LIB;

mosquitto在windows10中VS2019进行编译出lib和dll

 8.回到vs2019界面,选择Release和x64位环境,mosquitto工程目录下点击右键,选择生成

mosquitto在windows10中VS2019进行编译出lib和dll

9.会在mosquitto-vs\lib\Release下生成lib和dll,调用时会使用mosquitto.h头文件,从mosquitto-master\include目录下拷贝

mosquitto在windows10中VS2019进行编译出lib和dll

继续阅读