簡體   English   中英

使用 https://github.com/eclipse/paho.mqtt.cpp 和 cmake 構建

[英]Using https://github.com/eclipse/paho.mqtt.cpp with a cmake build

我對CMake有點CMake 所以這可能是一個菜鳥問題..

我正在嘗試使用CMake構建 cpp 項目。 我希望我的程序發布到 mqtt 經紀人。 我在 Linux 上運行。

所以我通過做(並排)安裝了https://github.com/eclipse/paho.mqtt.cpp和相應的 c 項目

$ git clone https://github.com/eclipse/paho.mqtt.c.git
$ cd paho.mqtt.c
$ git checkout v1.3.1

$ cmake -Bbuild -H. -DPAHO_WITH_SSL=ON -DPAHO_ENABLE_TESTING=OFF
$ sudo cmake --build build/ --target install
$ sudo ldconfig

根據文檔然后做。

$ git clone https://github.com/eclipse/paho.mqtt.cpp
$ mkdir build
$ cd build
$ cmake ../
$ make
$ sudo make install

一切正常,沒有任何錯誤。 所以我可以。

#include "mqtt/async_client.h"

int main(int argc, char *argv[]){
   std::cout << "Hello World!" << std::endl;
   mqtt::async_client cli(DFLT_ADDRESS, "", 120, PERSIST_DIR);


   return 0;
}

我試了一個簡單的。

cmake_minimum_required(VERSION 2.8.9)
project (hello)

find_package(PahoMqttCpp REQUIRED)


add_executable(hello helloworld.cpp)
target_link_libraries(hello ${PAHO_CPP_LIB})

但這似乎還不夠..我明白了

helloworld.cpp:(.text+0xd3): undefined reference to `mqtt::async_client::~async_client()'

任何幫助,將不勝感激。

好吧,經過一番挖掘,我發現正確的寫法是:

target_link_libraries(hello paho-mqttpp3 paho-mqtt3as)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM