I struggled the last few days too and I finally got it running.
I succeeded using the CMake GUI and the Developer Console from Visual Studio 2019.
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.
Installing paho.mqtt.c
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.
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/
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".
CMake GUI for paho.mqtt.c
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
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.
Installing paho.mqtt.cpp
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".
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.
In order to do this, configure the variables PAHO_MQTT_C_INCLUDE_DIRS
and PAHO_MQTT_C_LIBRARIES
.
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.
Finally, go back to the Developer Command Prompt, navigate to the paho.mqtt.cpp folder and run cmake --build build --target install
.
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
.
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.