When cross-compiling the Azure IoT SDK for C with CMake, it also tries to build some samples. But it doesn't link these samples against libcurl, i.e. -lcurl
is missing from the corresponding command line. Thus I am getting a lot of undefined references. For example:
../../../c-utility/libaziotsharedutil.a(httpapi_curl.c.o): In function `HTTPAPI_Init':
httpapi_curl.c:(.text+0x408): undefined reference to `curl_global_init'
This is how I call the build script:
cd azure-iot-sdk-c/build_all/linux && ./build.sh --toolchain-file ../../../_toolchain.cmake -cl --sysroot=$(ROOTFS_STAGING_PATH)
And this is how my toolchain file looks like:
INCLUDE(CMakeForceCompiler)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_C_COMPILER $ENV{TOOLCHAIN_PATH}/bin/$ENV{LNXP_TARGET}-gcc)
SET(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_PATH}/bin/$ENV{LNXP_TARGET}-g++)
SET(CMAKE_SYSROOT $ENV{ROOTFS_STAGING_PATH})
SET(CMAKE_FIND_ROOT_PATH $ENV{ROOTFS_STAGING_PATH})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CURL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../Supplies/curl/include)
SET(CURL_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/../../Supplies/curl/lib)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../Supplies/curl/include)
LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../Supplies/curl/lib)
SET(use_default_uuid ON CACHE BOOL "")
SET(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "")
I am misusing the toolchain file to set some options, because the build script doesn't let me set the options directly.
This is what the command line to build the samples looks like:
/<toolchain path>/arm-sc1x5-linux-gnueabihf-gcc --sysroot=/<sysroot path> --sysroot=/<sysroot path> -fPIC -Werror -rdynamic CMakeFiles/iothub_convenience_sample.dir/iothub_convenience_sample.c.o CMakeFiles/iothub_convenience_sample.dir/__/__/__/certs/certs.c.o -o iothub_convenience_sample -L/<curl path>/lib -Wl,-rpath,/<curl path>/lib:/usr/local/lib ../../libiothub_client.a ../../libiothub_client_http_transport.a ../../libiothub_client_amqp_transport.a ../../libiothub_client_amqp_ws_transport.a ../../../uamqp/libuamqp.a ../../../c-utility/libaziotsharedutil.a ../../libiothub_client_mqtt_transport.a ../../libiothub_client_mqtt_ws_transport.a ../../../umqtt/libumqtt.a ../../../libparson.a ../../../c-utility/libaziotsharedutil.a /<sysroot path>/usr/local/lib/libssl.so /<sysroot path>/usr/local/lib/libcrypto.so -lpthread -lm -lrt
What am I doping wrong?