简体   繁体   中英

Error in Paho MQTT C Client Library

I'm try to publish my data via MQTT in C and I'm use the sample code of ( Paho MQTT C Client Library link [ http://www.eclipse.org/paho/files/mqttdoc/MQTTClient/html/pubsync.html] ) but I'm getting some error like

--------------------------------------------------------------
D:\work\CB\TEST_RUNNING\hello\main.c|21|undefined reference to `MQTTClient_create'|
D:\work\CB\TEST_RUNNING\hello\main.c|26|undefined reference to `MQTTClient_connect'|
D:\work\CB\TEST_RUNNING\hello\main.c|35|undefined reference to `MQTTClient_publishMessage'|
D:\work\CB\TEST_RUNNING\hello\main.c|39|undefined reference to `MQTTClient_waitForCompletion'|
D:\work\CB\TEST_RUNNING\hello\main.c|41|undefined reference to `MQTTClient_disconnect'|
D:\work\CB\TEST_RUNNING\hello\main.c|42|undefined reference to `MQTTClient_destroy'|
||error: ld returned 1 exit status|
||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
------------------------------------------------------------

help me how to remove it and get my resutls

This is a linker error. The linker cannot resolve dependency to functions mentioned in the output. What you need is to provide path to the library -L option and also provide the library name -l option assuming that you are using gcc. In any case try to find a way to add library to your compilation flow.

It is basically a linker error.Include the library name after -l. Paho c client uses four different libraries.

  • paho-mqtt3a - asynchronous MQTTAsync
  • paho-mqtt3as - asynchronous with SSL MQTTAsync
  • paho-mqtt3c - synchronous MQTTClient
  • paho-mqtt3cs - synchronous with SSL MQTTClient

Eg: For compiling for synchronous publish code (sync_publish.c):

gcc sync_publish.c -lpaho-mqtt3c -o output

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM