I've created a simple application that uses the Azure IoT SDK for C to provision and connect to my Azure IoT Hub. This is cross-compiled using Debian for an ARM device.
This application builds and runs perfectly when I do a complete build of the SDK, because I developed my application based on one of the provided sample applications.
However, I would like to have my own custom build operation, with my own Makefile as below. I am linking in every .a library file that I get on the SDK, and also the required .so files on the target. My Makefile is as follows :
INC=-I./include/c-utility/inc -I./include/iothub_client/inc -I./include/serializer/inc -I./include/umqtt/inc -I./include/certificates -I./include/deps/umock-c/inc -I./include/deps/parson \
-I./include/deps/azure-macro-utils-c/inc -I./include/provisioning_client/inc
SOURCE_DIR=./src
LIBS_DIR=./libs
LIBS=-lrt -lgcc_s -lc -liothub_client -liothub_client_mqtt_transport -lprov_device_ll_client -lprov_device_client -luhttp -laziotsharedutil -lpthread -lcurl -lssl -lcrypto -lm -luuid -lparson -lprov_mqtt_transport -lprov_http_transport -lprov_mqtt_ws_transport -lprov_auth_client \
-liothub_client_mqtt_transport -lhsm_security_client -lumock_c -lumqtt -luamqp -lserializer -lprovisioning_service_client -lprov_mqtt_ws_transport -lprov_amqp_ws_transport -lprov_amqp_transport \
-liothub_service_client -liothub_client_http_transport -liothub_client_amqp_ws_transport -liothub_client_amqp_transport -lhsm_security_client -lprov_device_ll_client -lcustom_hsm_example
CC=/bin/arm-linux-gnueabi-gcc
CFLAGS= $(INC) -g -Wall -std=gnu99
DEPS=
default: runfile
runfile: custom_hsm_example.o prov_dev_client_sample.o
$(CC) $(CFLAGS) -o runfile custom_hsm_example.o prov_dev_client_sample.o -L$(LIBS_DIR) $(LIBS)
custom_hsm_example.o: $(SOURCE_DIR)/custom_hsm_example.c
$(CC) $(CFLAGS) -c $(SOURCE_DIR)/custom_hsm_example.c
prov_dev_client_sample.o: $(SOURCE_DIR)/prov_dev_client_sample.c
$(CC) $(CFLAGS) -c $(SOURCE_DIR)/prov_dev_client_sample.c
clean:
rm -rf *.o runfile
Somehow the build still fails with the following linking problems. I don't think I am missing any libraries. Would the order of libraries listed in the Makefile matter? I'd appreciate any help. Here is the output when I invoke the Makefile :
/bin/arm-linux-gnueabi-gcc -I./include/c-utility/inc -I./include/iothub_client/inc -I./include/serializer/inc -I./include/umqtt/inc -I./include/certificates -I./include/deps/umock-c/inc -I./include/deps/parson -I./include/deps/azure-macro-utils-c/inc -I./include/provisioning_client/inc -g -Wall -std=gnu99 -o runfile custom_hsm_example.o prov_dev_client_sample.o -L./libs -lrt -lgcc_s -lc -liothub_client -liothub_client_mqtt_transport -lprov_device_ll_client -lprov_device_client -luhttp -laziotsharedutil -lpthread -lcurl -lssl -lcrypto -lm -luuid -lparson -lprov_mqtt_transport -lprov_http_transport -lprov_mqtt_ws_transport -lprov_auth_client -liothub_client_mqtt_transport -lhsm_security_client -lumock_c -lumqtt -luamqp -lserializer -lprovisioning_service_client -lprov_mqtt_ws_transport -lprov_amqp_ws_transport -lprov_amqp_transport -liothub_service_client -liothub_client_http_transport -liothub_client_amqp_ws_transport -liothub_client_amqp_transport -lhsm_security_client -lprov_device_ll_client -lcustom_hsm_example
./libs/libprov_mqtt_transport.a(prov_transport_mqtt_client.c.o): In functionmqtt_transport_io':
prov_transport_mqtt_client.c:(.text+0x84): undefined reference to http_proxy_io_get_interface_description'
./libs/libumqtt.a(mqtt_message.c.o): In functionmqttmessage_getTopicLevels':
mqtt_message.c:(.text+0x96c): undefined reference to StringToken_Split'
./libs/libprov_device_ll_client.a(prov_device_ll_client.c.o): In functionprov_transport_challenge_callback':
prov_device_ll_client.c:(.text+0x354): undefined reference to prov_auth_import_key'
prov_device_ll_client.c:(.text+0x3e4): undefined reference toprov_auth_construct_sas_token'
./libs/libprov_device_ll_client.a(prov_device_ll_client.c.o): In function on_transport_registration_data':
prov_device_ll_client.c:(.text+0x2348): undefined reference toprov_auth_import_key'
./libs/libprov_device_ll_client.a(prov_device_ll_client.c.o): In function destroy_instance':
prov_device_ll_client.c:(.text+0x28a4): undefined reference toprov_auth_destroy'
./libs/libprov_device_ll_client.a(prov_device_ll_client.c.o): In function Prov_Device_LL_Create':
prov_device_ll_client.c:(.text+0x2acc): undefined reference toprov_auth_create'
prov_device_ll_client.c:(.text+0x2be0): undefined reference to prov_auth_get_type'
./libs/libprov_device_ll_client.a(prov_device_ll_client.c.o): In functionProv_Device_LL_Register_Device':
prov_device_ll_client.c:(.text+0x2e8c): undefined reference to prov_auth_get_registration_id'
prov_device_ll_client.c:(.text+0x2fd4): undefined reference toprov_auth_get_endorsement_key'
prov_device_ll_client.c:(.text+0x3084): undefined reference to prov_auth_get_storage_key'
prov_device_ll_client.c:(.text+0x3158): undefined reference toprov_auth_get_certificate'
prov_device_ll_client.c:(.text+0x3208): undefined reference to prov_auth_get_alias_key'
./libs/libprov_device_ll_client.a(prov_device_ll_client.c.o): In functionProv_Device_LL_SetOption':
prov_device_ll_client.c:(.text+0x4120): undefined reference to prov_auth_set_registration_id'
collect2: error: ld returned 1 exit status
make: *** [Makefile:17: runfile] Error 1
Same question on SO for reference: https://stackoverflow.com/questions/62594208/azure-iot-c-sdk-library-linking-problem
Same question on SO for reference: https://stackoverflow.com/questions/62594208/azure-iot-c-sdk-library-linking-problem
@asergaz It's removed to avoid duplicates.
Please review the previous github issues
https://github.com/Azure/azure-iot-sdk-c/search?q=StringToken_Split&type=Issues
Please review the previous github issues
https://github.com/Azure/azure-iot-sdk-c/search?q=StringToken_Split&type=Issues
@ericwol-msft Those examples are using CMake. I'm trying to compile this by just using Make.
Basically, I located all the library files that were built with the SDK, copied them to a single folder and I link my application against all of the libraries. I'm not sure what i'm missing here exactly.
Hello @jebrando . I saw you reply to a similar problem previously and perhaps you might be able to help.
Basically, i'm trying to build a C application for provisioning and communication. I don't want to depend on the CMake files included with the SDK etc.
Below is my own Makefile, and the output is below it. I don't know why the linker has issues finding them functions. Am I missing any other libraries, or flags? Thanks in advance.
INC=-I./include/c-utility/inc -I./include/iothub_client/inc -I./include/serializer/inc -I./include/umqtt/inc -I./include/certificates -I./include/deps/umock-c/inc -I./include/deps/parson \
-I./include/deps/azure-macro-utils-c/inc -I./include/provisioning_client/inc
SOURCE_DIR=./src
LIBS_DIR=./libs
LIBS=\
-liothub_client \
-liothub_client_http_transport \
-luhttp \
-liothub_client_mqtt_transport \
-lumqtt \
-lrt \
-lgcc_s \
-lc \
-lprov_device_ll_client \
-lprov_device_client \
-liothub_service_client \
-laziotsharedutil \
-lpthread \
-lcurl \
-lssl \
-lcrypto \
-lm \
-luuid \
-lparson \
-lprov_mqtt_transport \
-lprov_http_transport \
-lprov_auth_client \
-lhsm_security_client \
-lumock_c \
-luamqp \
-lserializer \
-lprovisioning_service_client \
-lprov_mqtt_ws_transport \
-lprov_amqp_ws_transport \
-lprov_amqp_transport \
-liothub_client_amqp_ws_transport \
-liothub_client_amqp_transport \
-lhsm_security_client
CC=/home/bin/arm-linux-gnueabi-gcc
CFLAGS= $(INC) -g -Wall -std=gnu99
DEPS=
default: runfile
runfile: custom_hsm_example.o prov_dev_client_sample.o
$(CC) $(CFLAGS) -o runfile custom_hsm_example.o prov_dev_client_sample.o -L$(LIBS_DIR) $(LIBS)
custom_hsm_example.o: $(SOURCE_DIR)/custom_hsm_example.c
$(CC) $(CFLAGS) -c $(SOURCE_DIR)/custom_hsm_example.c
prov_dev_client_sample.o: $(SOURCE_DIR)/prov_dev_client_sample.c
$(CC) $(CFLAGS) -c $(SOURCE_DIR)/prov_dev_client_sample.c
clean:
rm -rf *.o runfile
Output :
/home/bin/arm-linux-gnueabi-gcc -I./include/c-utility/inc -I./include/iothub_client/inc -I./include/serializer/inc -I./include/umqtt/inc -I./include/certificates -I./include/deps/umock-c/inc -I./include/deps/parson -I./include/deps/azure-macro-utils-c/inc -I./include/provisioning_client/inc -g -Wall -std=gnu99 -use_prov_client:BOOL=ON -o runfile custom_hsm_example.o prov_dev_client_sample.o -L./libs -liothub_client -liothub_client_http_transport -luhttp -liothub_client_mqtt_transport -lumqtt -lrt -lgcc_s -lc -lprov_device_ll_client -lprov_device_client -liothub_service_client -laziotsharedutil -lpthread -lcurl -lssl -lcrypto -lm -luuid -lparson -lprov_mqtt_transport -lprov_http_transport -lprov_auth_client -lhsm_security_client -lumock_c -luamqp -lserializer -lprovisioning_service_client -lprov_mqtt_ws_transport -lprov_amqp_ws_transport -lprov_amqp_transport -liothub_client_amqp_ws_transport -liothub_client_amqp_transport -lhsm_security_client
./libs/libprov_device_client.a(prov_device_client.c.o): In function `ScheduleWork_Thread':
prov_device_client.c:(.text+0x80): undefined reference to `Prov_Device_LL_DoWork'
./libs/libprov_device_client.a(prov_device_client.c.o): In function `Prov_Device_Create':
prov_device_client.c:(.text+0x3d8): undefined reference to `Prov_Device_LL_Create'
./libs/libprov_device_client.a(prov_device_client.c.o): In function `Prov_Device_Destroy':
prov_device_client.c:(.text+0x668): undefined reference to `Prov_Device_LL_Destroy'
./libs/libprov_device_client.a(prov_device_client.c.o): In function `Prov_Device_Register_Device':
prov_device_client.c:(.text+0x7f0): undefined reference to `Prov_Device_LL_Register_Device'
./libs/libprov_device_client.a(prov_device_client.c.o): In function `Prov_Device_SetOption':
prov_device_client.c:(.text+0xa3c): undefined reference to `Prov_Device_LL_SetOption'
./libs/libprov_device_client.a(prov_device_client.c.o): In function `Prov_Device_GetVersionString':
prov_device_client.c:(.text+0xaf8): undefined reference to `Prov_Device_LL_GetVersionString'
./libs/libprov_device_client.a(prov_device_client.c.o): In function `Prov_Device_Set_Provisioning_Payload':
prov_device_client.c:(.text+0xb9c): undefined reference to `Prov_Device_LL_Set_Provisioning_Payload'
./libs/libprov_device_client.a(prov_device_client.c.o): In function `Prov_Device_Get_Provisioning_Payload':
prov_device_client.c:(.text+0xc4c): undefined reference to `Prov_Device_LL_Get_Provisioning_Payload'
./libs/libprov_mqtt_transport.a(prov_transport_mqtt_client.c.o): In function `mqtt_transport_io':
prov_transport_mqtt_client.c:(.text+0x84): undefined reference to `http_proxy_io_get_interface_description'
collect2: error: ld returned 1 exit status
make: *** [Makefile:48: runfile] Error 1
Hi @pmulligan-rk , these functions are defined in the prov_device_ll_client library.
I see you have it in your link list, but it could be that the linker is failing to find them because of the order of the libraries in your list.
Could you try moving -lprov_device_ll_client to after -lprov_device_client ?
I'm going to go ahead and close this for inactivity. If anyone is still having issues please make a comment here and we can reopen.
@pmulligan-rk, @ericwol-msft, @danewalton, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey