admin管理员组文章数量:1389981
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.
本文标签:
版权声明:本文标题:dll - Linking mosquitto library in windows to avoid compiler errors "cannot find -lmosquitto" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744666025a2618536.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论