This seems like a pretty straightforward question at this point, but I cannot for the life of me find a solution anywhere that works for me. I'm trying to do a very simple client development in C using the mosquitto library and broker. Downloaded and used the prebuilt installer. I have the broker up and running and can publish fine using the command line. I've written a small client module in C:
#include <stdio.h>
#include "mosquitto.h"
int main () {
int rc;
struct mosquitto * vsp_client;
mosquitto_lib_init();
vsp_client = mosquitto_new("vsp", true, NULL);
rc = mosquitto_connect(vsp_client, "localhost", 1883, 60);
if(rc != 0) {
printf("VSP client could not connecto to broker! Error Code: %d\n", rc);
mosquitto_destroy(vsp_client);
return -1;
}
printf("We are now connected to the broker!\n");
mosquitto_publish(vsp_client, NULL, "test/t1", 6, "Hello", 0, false);
mosquitto_disconnect(vsp_client);
mosquitto_destroy(vsp_client);
mosquitto_lib_cleanup();
return 0;
};
To compile this I'm using:
gcc vsp.c -o vsp -lmosquitto
Initially I had issues with the header, and because I installed it to the default location, the header is at [c:\Program Files\mosquitto\devel]. Easy enough, I added the directory to be included with gcc:
gcc vsp.c -o vsp -lmosquitto -I"C:Program Files\mosquitto\devel"
(Similarly moved "-lmosquitto" to the end of the command and same result)
But I now get :
$ gcc vsp.c -o vsp -I"C:\Program Files\mosquitto\devel" -lmosquitto /usr/lib/gcc/i686-pc-cygwin/7.4.0/../../../../i686-pc-cygwin/bin/ld: cannot find -lmosquitto collect2: error: ld returned 1 exit status
What do I still have to do to link this library?
[EDIT]
I linked the library at compile time using:
gcc vsp.c -o vsp -lmosquitto -I"C:\Program Files\mosquitto\devel" -L"C:Program Files\mosquitto\devel"
And it built! But now when I try to run the executable I get:
$ ./vsp
C:/Program Files/mosquitto/devel/vsp.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
Any insights into what I need to do to get this library working would be greatly appreciated.