Reputation:
I followed the offical documentation and the MS Azure IOT SDK for C guide described here
https://learn.microsoft.com/de-de/azure/iot-hub/iot-hub-device-sdk-c-intro
to build my very simple own client to send MQTT messages. But on a ubuntu machine I am not able to get this client to work. Compiling and linking is done with cmake and make. But the make VERBOSE=1 command runs in "undefined reference" errors (see screenshot). I thought all libraries were available in the system after installing the SDK via apt-get. But now it seems so, that some are missing. Could you give me an information about what libs are missing or a way to find out which are non existent (maybe one is the parson lib)? This is the make/linker output (only some lines of some more lines):
/usr/bin/cmake -E cmake_link_script CMakeFiles/mqttsender.dir/link.txt --verbose=1 /usr/bin/cc -rdynamic CMakeFiles/mqttsender.dir/mqttsender.c.o -o mqttsender -liothub_client -liothub_client_mqtt_transport -laziotsharedutil -lssl -lpthread -lcurl -lssl -lcrypto -lm -lpthread -lcurl -lcrypto -lm /usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/libiothub_client.a(iothub_client_ll_uploadtoblob.c.o): In function
parse_result_json': iothub_client_ll_uploadtoblob.c:(.text+0x334): undefined reference to
json_parse_string'" /usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/libiothub_client_mqtt_transport.a(iothubtransport_mqtt_common.c.o): In functionfree_transport_handle_data': iothubtransport_mqtt_common.c:(.text+0x1e0): undefined reference to
mqtt_client_deinit' /usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/libiothub_client_mqtt_transport.a(iothubtransport_mqtt_common.c.o): In functionpublish_mqtt_telemetry_msg': iothubtransport_mqtt_common.c:(.text+0x1989): undefined reference to
mqttmessage_create_in_place' iothubtransport_mqtt_common.c:(.text+0x1a63): undefined reference tomqtt_client_publish' iothubtransport_mqtt_common.c:(.text+0x1ad8): undefined reference to
mqttmessage_destroy' /usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/libiothub_client_mqtt_transport.a(iothubtransport_mqtt_common.c.o): In functionpublish_device_method_message': iothubtransport_mqtt_common.c:(.text+0x1bc6): undefined reference to
mqttmessage_create_in_place' iothubtransport_mqtt_common.c:(.text+0x1c32): undefined reference tomqtt_client_publish' iothubtransport_mqtt_common.c:(.text+0x1c93): undefined reference to
mqttmessage_destroy' /usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/libiothub_client_mqtt_transport.a(iothubtransport_mqtt_common.c.o): In functionpublish_device_twin_get_message': iothubtransport_mqtt_common.c:(.text+0x1e65): undefined reference to
mqttmessage_create' iothubtransport_mqtt_common.c:(.text+0x1ed4): undefined reference tomqtt_client_publish' iothubtransport_mqtt_common.c:(.text+0x1f52): undefined reference to
mqttmessage_destroy'"
Here is the CMakelists.txt:
> cmake_minimum_required(VERSION 2.8.11)
set(AZUREIOT_INC_FOLDER ".." "/usr/include/azureiot")
include_directories(${AZUREIOT_INC_FOLDER})
set(my_c_files
./mqttsender.c
)
add_executable(mqttsender ${my_c_files})
target_link_libraries(mqttsender
iothub_client
iothub_client_mqtt_transport
aziotsharedutil
ssl
pthread
curl
ssl
crypto
m
)
Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include "iothub.h" //located at "/usr/include/azureiot/"
#include "iothubtransportmqtt.h" //for mqtt protocol types
#include "iothub_client.h"
int main()
{ int myrv;
myrv = IoTHub_Init();
char myconnectionstring[] = "blablablabla";
printf("IoTHub_Init returns %d\n", myrv);
if (IoTHubClient_LL_CreateFromConnectionString(myconnectionstring, MQTT_Protocol) == NULL)
{
(void)printf("ERROR: got no handle!\r\n");
}
else
{
(void)printf("INFORMATION: yeah, there is a handle!\n");
}
IoTHub_Deinit();
printf("IoTHub_Deinit done.\n");
return 0;
}
Thanks.
Upvotes: 0
Views: 1157
Reputation:
One step that helps was to add the parson library inside the CMakeLists.txt. Just added the line "parson" in the target_link_libraries section. Another step was to add the umqtt library inside the same section instead having nothing there resp. "uamqp" like in the example given here: https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/ubuntu_apt-get_sample_setup.md#create-an-application-using-cmake
So now my CMakeLists.txt looks this way:
cmake_minimum_required(VERSION 2.8.11)
set(AZUREIOT_INC_FOLDER ".." "/usr/include/azureiot" "/usr/include/azureiot/inc")
include_directories(${AZUREIOT_INC_FOLDER})
set(my_c_files
./mqttsender.c
)
add_executable(mqttsender ${my_c_files})
target_link_libraries(mqttsender
iothub_client
iothub_client_mqtt_transport
umqtt
aziotsharedutil
ssl
pthread
curl
ssl
crypto
m
parson
)
And my mqttclient can be compiled and is linked correctly :)
Hope that this will help somebody and sometimes.
Upvotes: 1