1、问题描述
使用编译好的库文件,从githup上下载头文件,运行时MQTTClient_connect调用失败,返回MQTTCLIENT_BAD_STRUCTURE;
MQTTCLIENT_BAD_STRUCTURE在MQTTClient.h中是struct_id或struct_version 不正确,其定义为:
/**
* Return code: A structure parameter does not have the correct eyecatcher
* and version number.
*/
#define MQTTCLIENT_BAD_STRUCTURE -8
2、问题原因
该问题是由于mqtt库版本为1.1,而头文件版本为1.3,1.3版本的mqtt struct_version 值为6,在1.1版本不兼容,以下是mqtt 1.1和1.3版本MQTTClient_connect函数部分代码:
//paho mqtt 1.1版本
int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
{
MQTTClients* m = handle;
int rc = SOCKET_ERROR;
FUNC_ENTRY;
Thread_lock_mutex(connect_mutex);
Thread_lock_mutex(mqttclient_mutex);
if (options ==