如何在Windows上构建Paho MQTT C ++ [英] How to build paho mqtt c++ on windows

查看:1340
本文介绍了如何在Windows上构建Paho MQTT C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在azure iot hub上上传一些json数据.我正在用C ++编写代码,需要mqtt才能将所有数据发布到物联网中心.我指的是这个github页面: https://github.com/eclipse/paho.mqtt.cpp

I have few json data which I need to upload on azure iot hub. I am writing code in c++ and need mqtt to publish all the data to iot hub. I am referring this github page: https://github.com/eclipse/paho.mqtt.cpp

但是关于如何构建它的说明有些混乱,似乎没有用.谁能解释我如何在Windows中安装mqtt并将其与Visual Studio c ++一起使用.请帮忙.谢谢

But instruction on how to build it is a bit confusing and not seems to be working. Can anyone please explain how can I install mqtt in windows and can use it with visual studio c++. Please help. Thanks

推荐答案

最近几天我也很努力,终于让它运行了.

I struggled the last few days too and I finally got it running.

我成功使用了Visual Studio 2019中的CMake GUI和开发者控制台.

I succeeded using the CMake GUI and the Developer Console from Visual Studio 2019.

我(有点)遵循的指示是:<​​a href="https://github.com/eclipse/paho.mqtt.cpp" rel="nofollow noreferrer"> https://github.com/eclipse/paho.mqtt.cpp .向下滚动到Windows部分,实际上非常简单.但是,我没有使用cmake -BBuild ...命令的终端,而是使用CMake GUI,在此我适当地配置了变量.

The instructions I (kinda) followed, were these: https://github.com/eclipse/paho.mqtt.cpp. Scroll down to the Windows part, it's actually very straight forward. However, instead of using the terminal for the cmake -BBuild ... commands I used the CMake GUI, where I configured the variables appropriately.

因此,如使用说明所述,您首先需要安装paho.mqtt.c.为此,只需在您的计算机上的某个位置克隆存储库即可.在paho.mqtt.c文件夹中,创建一个"build"文件夹.

So, as mentioned on the instructions, you first need to install paho.mqtt.c. For that, just clone the repo somewhere on your machine. Inside the paho.mqtt.c folder create a "build" folder.

打开CMake GUI,然后单击浏览源"并设置克隆存储库的文件夹../paho.mqtt.c/. 对于浏览构建",选择您刚刚创建的构建文件夹../paho.mqtt.c/build/

Open the CMake GUI, then click on "Browse Source" and set the folder where the repo was cloned ../paho.mqtt.c/. For "Browse Build" select the build folder you just created ../paho.mqtt.c/build/

单击配置"(我使用默认的Generator Visual Studio 16 2019).在这种情况下,我没有触摸配置变量,所以我继续并单击生成".

The click on "Configure" (I used the default Generator Visual Studio 16 2019). At this instance I didn't touch the configuration variables, so I just went ahead and clicked on "Generate".

用于paho.mqtt.c的CMake GUI

然后,打开开发人员控制台(按Windows键,键入"developer",然后打开VS 2019或任何使用的版本的Developer Command Prompt),并导航到paho.mqtt.c文件夹.在那里,根据github页面上的说明,键入命令:

Then, open a developer console (press the windows key, type "developer" and open the Developer Command Prompt for VS 2019, or whatever version you use) and navigate to the paho.mqtt.c folder. There, according to the instructions on the github page, type the command:

cmake --build build --target install

这会将paho.mqtt.c安装在C:\Program Files(x86)\Eclipse Paho C\中.请注意,可以通过将CMake GUI上的CMAKE_INSTALL_PREFIX变量修改为自定义位置来更改此位置.

This will install the paho.mqtt.c in C:\Program Files(x86)\Eclipse Paho C\. Note that this location can be changed by modifying the CMAKE_INSTALL_PREFIX variable on the CMake GUI to a custom location.

该过程本质上是相同的:打开CMake GUI,选择包含源的文件夹,然后选择build文件夹,然后单击配置".

The procedure is in nature the same: open the CMake GUI, select the folder that contains the source, then the build folder and then click on "Configure".

现在,由于paho.mqtt.cpp依赖paho.mqtt.c中的库,因此您必须告诉cmake在哪里可以找到相应的paho.mqtt.c库.

Now, since paho.mqtt.cpp relies on libraries from paho.mqtt.c, you must tell cmake where to find the corresponding paho.mqtt.c libraries.

为此,请配置变量PAHO_MQTT_C_INCLUDE_DIRSPAHO_MQTT_C_LIBRARIES.

In order to do this, configure the variables PAHO_MQTT_C_INCLUDE_DIRS and PAHO_MQTT_C_LIBRARIES.

    在我的情况下,
  • PAHO_MQTT_C_INCLUDE_DIRS应该指向paho.mqtt.c安装内的"include"文件夹:C:/Program Files (x86)/Eclipse Paho C/include
  • PAHO_MQTT_C_LIBRARIES在我的情况下,我设置为指向paho-mqtt3c.dll:C:/Program Files (x86)/Eclipse Paho C/bin/paho-mqtt3c.dll
  • PAHO_MQTT_C_INCLUDE_DIRS should point to the "include" folder inside the paho.mqtt.c installation, in my case: C:/Program Files (x86)/Eclipse Paho C/include
  • PAHO_MQTT_C_LIBRARIES I set up to point to the paho-mqtt3c.dll, in my case: C:/Program Files (x86)/Eclipse Paho C/bin/paho-mqtt3c.dll

我保持不变的其他选择.

The other options I left untouched.

最后,返回到开发人员命令提示符",导航到paho.mqtt.cpp文件夹并运行cmake --build build --target install.

Finally, go back to the Developer Command Prompt, navigate to the paho.mqtt.cpp folder and run cmake --build build --target install.

如果一切顺利,则会根据配置变量CMAKE_INSTALL_PREFIX将paho.mqtt.cpp安装在C:/Program Files (x86)/paho-mqtt-cpp中.

If everything goes well, paho.mqtt.cpp will be installed in C:/Program Files (x86)/paho-mqtt-cpp, according to the configuration variable CMAKE_INSTALL_PREFIX.

现在,您可以在c ++项目中引用这两个库.请注意,如果要在项目上使用paho.mqtt.cpp库,还必须包括paho.mqtt.c.

Now, you can reference both libraries in your c++ projects. Be aware that if you want to use the paho.mqtt.cpp library on your project you'll also have to include paho.mqtt.c.

这篇关于如何在Windows上构建Paho MQTT C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆