Azure / azure-iot-sdk-c

A C99 SDK for connecting devices to Microsoft Azure IoT services
https://azure.github.io/azure-iot-sdk-c
Other
587 stars 739 forks source link

Undefined references to iothub_device_xxx upgrading from LTS_01_2022_Ref01 to LTS_07_2022_Ref01 #2494

Closed RandySRSOL closed 1 year ago

RandySRSOL commented 1 year ago

Ubuntu 20.04, Cross Compiled on Ubuntu 20.04 using GCC 9.4.0

Release LTS_07_2022_Ref01

I'm getting Linker errors starting with LTS_07_2022_Ref01 - LTS_01_2023_Ref02

I've been using iot hub for a couple of years and I wanted to upgrade from LTS_01_2022_Ref01 to the latest version. Compiling I get these linker errors.

/usr/bin/ld: ../../../iot/azure-iot-sdk/src/azure-iot-build/iothub_client/libiothub_client_amqp_ws_transport.a(iothub_client_authorization.c.o): in function IoTHubClient_Auth_CreateFromDeviceAuth': iothub_client_authorization.c:(.text+0x329): undefined reference toiothub_device_auth_create' /usr/bin/ld: iothub_client_authorization.c:(.text+0x384): undefined reference to iothub_device_auth_get_type' /usr/bin/ld: ../../../iot/azure-iot-sdk/src/azure-iot-build/iothub_client/libiothub_client_amqp_ws_transport.a(iothub_client_authorization.c.o): in functionIoTHubClient_Auth_Destroy': iothub_client_authorization.c:(.text+0x3d8): undefined reference to iothub_device_auth_destroy' /usr/bin/ld: ../../../iot/azure-iot-sdk/src/azure-iot-build/iothub_client/libiothub_client_amqp_ws_transport.a(iothub_client_authorization.c.o): in functionIoTHubClient_Auth_Set_xio_Certificate': iothub_client_authorization.c:(.text+0x520): undefined reference to iothub_device_auth_generate_credentials' /usr/bin/ld: ../../../iot/azure-iot-sdk/src/azure-iot-build/iothub_client/libiothub_client_amqp_ws_transport.a(iothub_client_authorization.c.o): in functionIoTHubClient_Auth_Get_x509_info': iothub_client_authorization.c:(.text+0x608): undefined reference to iothub_device_auth_generate_credentials' /usr/bin/ld: ../../../iot/azure-iot-sdk/src/azure-iot-build/iothub_client/libiothub_client_amqp_ws_transport.a(iothub_client_authorization.c.o): in functionIoTHubClient_Auth_Get_SasToken': iothub_client_authorization.c:(.text+0x781): undefined reference to `iothub_device_auth_generate_credentials' collect2: error: ld returned 1 exit status

Here is the CMake I'm using.

set(CMAKE_IOTHUB_ARGS ${CMAKE_ARGS} "-Dno_logging=ON")

ExternalProject_Add( azure-iot GIT_REPOSITORY https://github.com/Azure/azure-iot-sdk-c.git GIT_TAG "LTS_01_2023_Ref02" GIT_SHALLOW true PREFIX ${IOT_PREFIX} CMAKE_ARGS "${CMAKE_IOTHUB_ARGS}" INSTALL_COMMAND "" )

set(IOT_LIBS ${IOT_BUILD}/iothub_client/libiothub_client_amqp_transport.a ${IOT_BUILD}/iothub_client/libiothub_client_amqp_ws_transport.a ${IOT_BUILD}/iothub_client/libiothub_client_http_transport.a ${IOT_BUILD}/iothub_client/libiothub_client_mqtt_transport.a ${IOT_BUILD}/iothub_client/libiothub_client_mqtt_ws_transport.a ${IOT_BUILD}/iothub_client/libiothub_client.a ${IOT_BUILD}/deps/parson/libparson.a ${IOT_BUILD}/c-utility/libaziotsharedutil.a ${IOT_BUILD}/umqtt/libumqtt.a ${IOT_BUILD}/uamqp/libuamqp.a ${OPENSSL_LIBRARIES} ssl crypto uuid curl )

include_directories(include
${CMAKE_HOME_DIRECTORY}/loggers/include
${CMAKE_HOME_DIRECTORY}/common/include
SYSTEM ${IOT_SRC}/c-utility/inc
SYSTEM ${IOT_SRC}/iothub_client/inc
SYSTEM ${IOT_SRC}/deps/parson
SYSTEM ${IOT_SRC}/deps/umock-c/inc
SYSTEM ${IOT_SRC}/deps/azure-macro-utils-c/inc
SYSTEM ${IOT_SRC}/deps/uhttp/inc
SYSTEM ${IOT_SRC}/deps/azure-c-testrunnerswitcher/inc
SYSTEM ${IOT_SRC}/provisioning_client/azure_prov_client/inc
${OPENSSL_INCLUDE_DIR}
${POCO_INCLUDE_DIR}
)
ericwolz commented 1 year ago

This was added for PR, Adding X509 PEM support for Provisioning Client (#2229)

Please set your project cmake option use_prov_client to OFF.

ewertons commented 1 year ago

Hey @RandySRSOL , please follow the recommendation from @ericwol-msft .

I created a CMakeLists.txt based on yours and got a repro of your issue. Then I added the cmake arg to disable the provisioning client, and the build worked.

cmake_minimum_required(VERSION 3.16)
project(iotsample)

include(ExternalProject)

set(CMAKE_IOTHUB_ARGS "-Duse_prov_client=OFF")

ExternalProject_Add(
azure-iot
GIT_REPOSITORY https://github.com/Azure/azure-iot-sdk-c.git
GIT_TAG "LTS_01_2023_Ref02"
GIT_SHALLOW false
PREFIX ${IOT_PREFIX}
CMAKE_ARGS "${CMAKE_IOTHUB_ARGS}"
INSTALL_COMMAND ""
)

ExternalProject_Get_property(azure-iot SOURCE_DIR)
ExternalProject_Get_property(azure-iot DOWNLOAD_DIR)
ExternalProject_Get_property(azure-iot BINARY_DIR)
ExternalProject_Get_property(azure-iot INSTALL_DIR)

set(IOT_BUILD ${BINARY_DIR})
set(IOT_SRC ${SOURCE_DIR})

set(IOT_LIBS
${IOT_BUILD}/iothub_client/libiothub_client_amqp_transport.a
${IOT_BUILD}/iothub_client/libiothub_client_amqp_ws_transport.a
${IOT_BUILD}/iothub_client/libiothub_client_http_transport.a
${IOT_BUILD}/iothub_client/libiothub_client_mqtt_transport.a
${IOT_BUILD}/iothub_client/libiothub_client_mqtt_ws_transport.a
${IOT_BUILD}/iothub_client/libiothub_client.a
${IOT_BUILD}/deps/parson/libparson.a
${IOT_BUILD}/umqtt/libumqtt.a
${IOT_BUILD}/uamqp/libuamqp.a
${IOT_BUILD}/c-utility/libaziotsharedutil.a
${OPENSSL_LIBRARIES}
ssl
crypto
uuid
curl
)

include_directories(include
${CMAKE_HOME_DIRECTORY}/loggers/include
${CMAKE_HOME_DIRECTORY}/common/include
SYSTEM ${IOT_SRC}/c-utility/inc
SYSTEM ${IOT_SRC}/iothub_client/inc
SYSTEM ${IOT_SRC}/deps/parson
SYSTEM ${IOT_SRC}/deps/umock-c/inc
SYSTEM ${IOT_SRC}/deps/azure-macro-utils-c/inc
SYSTEM ${IOT_SRC}/deps/uhttp/inc
SYSTEM ${IOT_SRC}/deps/azure-c-testrunnerswitcher/inc
SYSTEM ${IOT_SRC}/provisioning_client/azure_prov_client/inc
${OPENSSL_INCLUDE_DIR}
${POCO_INCLUDE_DIR}
)

add_executable(iotsample
        iothub_ll_telemetry_sample.c
)

target_link_libraries(iotsample
    ${IOT_LIBS}
    pthread
    m
)

The key is set(CMAKE_IOTHUB_ARGS "-Duse_prov_client=OFF").

Also, note that in your list you should link libaziotsharedutil.a last, after libuamqp.a and libumqtt.a. If your are curious, iothub_ll_telemetry_sample.c comes from one of our samples.

RandySRSOL commented 1 year ago

That fixed it! Thanks for the quick reply and sample code :-)

ericwolz commented 1 year ago

closing issue