Using Mosquitto with Visual Studio 2019

334 Views Asked by At

I'm trying to write a simple MQTT client command line application.

#include <iostream>
#include <mosquittopp.h>
int main()
{
    int a, b, c;
    mosquitto_lib_version(&a, &b, &c);
}

Whenever I call mosquitto_lib_version I get the following error (the same for any other mosquitto function). error LNK2019: unresolved external symbol __imp__mosquitto_lib_version referenced in function _main.

I installed Mosquitto (32-bit) and tested the broker using command line tools. I ensured that the relevant .h, .cpp and .lib files are present in --> C:\Program Files (x86)\mosquitto\devel. I specified the following properties for the project:

  • VC++ Directories | Include Directories --> C:\Program Files (x86)\mosquitto\devel
  • VC++ Directories | External Include Directories --> C:\Program Files (x86)\mosquitto\devel
  • VC++ Directories | Library Directories --> C:\Program Files (x86)\mosquitto\devel
  • VC++ Directories | Source Directories --> C:\Program Files (x86)\mosquitto\devel
  • Linker | Additional Library Directories --> C:\Program Files (x86)\mosquitto\devel
  • Linker | Input | Additional Dependencies --> mosquittopp.lib

I tried running VS in normal and admin mode.

I'm building for Win32, in Debug Mode.

All the above failing, I added NuGet package for Mosquitto 1.0.2 to no effect as well.

-------------UPDATE--------------

It was a mistake on my part: I only added mosquittopp.lib to Additional Dependencies of the linker. I should've added mosquitto.lib as well. Obviously all the DLLs from Mosquitto installation directory need to be in the same directory as my exe (or visible to VS in another way).

0

There are 0 best solutions below