简体   繁体   English

为 C++ 安装和使用 MQTT Paho 库

[英]Install and use MQTT Paho libraries for C++

I hope my problem is simple to resolve.我希望我的问题很容易解决。 I should to use mqtt protocol with my Raspberry Pi v2, so now I'm trying it with Paho libraries:我应该在我的 Raspberry Pi v2 中使用 mqtt 协议,所以现在我正在尝试使用 Paho 库:

http://www.eclipse.org/paho/ http://www.eclipse.org/paho/

I use C++ language, so I wrote first these commands我使用C++语言,所以我先写了这些命令

git clone http://git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.c.git
cd org.eclipse.paho.mqtt.c.git
make
sudo make install

and then these然后这些

git clone http://git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.cpp.git
cd org.eclipse.paho.mqtt.cpp.git
make

Now I have two questions:现在我有两个问题:

  1. What's the library that I have to include in my file?我必须包含在我的文件中的库是什么? I'm trying to compile the example in the Paho's site https://www.eclipse.org/paho/clients/cpp/ but if I include the C library "MQTTClient.h" (in the C example) it doesn't recognize the classes, like mqtt::client .我正在尝试编译 Paho 站点https://www.eclipse.org/paho/clients/cpp/ 中的示例,但如果我包含 C 库“MQTTClient.h”(在 C 示例中),则不会识别类,例如mqtt::client I have tried to include client.h (i found it in the documentation) but the compiler doesn't find it.我试图包含client.h (我在文档中找到了它)但编译器没有找到它。
  2. Why the C++ procedure to start Paho's libraries doesn't install nothing?为什么启动 Paho 库的 C++ 程序没有安装任何东西? There is only the make command that creates library lib/linmqttpp.so.0.1 .只有创建库lib/linmqttpp.so.0.1的 make 命令。 I must link it in the compile command?我必须在编译命令中链接它吗? How?如何?

currently in the paho c++ in the git project it is not building correctly for new users.当前在 git 项目的 paho c++ 中,它没有为新用户正确构建。 it creates an empty c++ library when you do a make so any code you link against that will fail with undefined method.当您执行 make 时,它​​会创建一个空的 C++ 库,因此您链接的任何代码都将因未定义的方法而失败。 you can check by running this command to see what is available in your library.您可以通过运行此命令来查看库中的可用内容。

nm -g lib/linmqttpp.so.0.1

You will see it is empty.你会看到它是空的。

Also if you copied and passed the example code from the website then it will not work.此外,如果您从网站复制并传递了示例代码,则它将无法正常工作。 It needs other code beside what is on the website.除了网站上的内容之外,它还需要其他代码。 It just gives you a code snippet.它只是给你一个代码片段。

Example code is in this directory.示例代码在此目录中。 src/samples

paho c++ examples paho C++ 示例

Currently the make file for the sample files will fail.目前,示例文件的 make 文件将失败。

I have submitted a patch just now to the project to fix the main build and the sample files build.我刚刚向项目提交了一个补丁来修复主构建和示例文件构建。 Once that is applied the project will build correctly you can start hacking the sample files.一旦应用,项目将正确构建,您可以开始破解示例文件。

With regards the C++ project not installing its because there is no target in the make file to do an install.关于 C++ 项目没有安装它,因为 make 文件中没有目标来进行安装。 if you want for now copy the files that are created in lib to the below with sudo permissions.如果您现在想要使用 sudo 权限将在 lib 中创建的文件复制到下面。 /usr/local/lib/ /usr/local/lib/

Then you can access the shared libraries from any project.然后您可以从任何项目访问共享库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM