1

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?

Jan Schatz
  • 334
  • 2
  • 12
  • 1
    Did you follow up with this [document](https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/devbox_setup.md#build-the-c-sdk-in-linux) to build the source code? I can compile successfully on Linux via following this document. Did you execute the command `sudo apt-get install -y git cmake build-essential curl libcurl4-openssl-dev libssl-dev uuid-dev` before compile the code? – Michael Xu Sep 03 '18 at 07:11
  • 1
    No, I followed this [document](https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/SDK_cross_compile_example.md). When not cross-compiling, finding curl is not an issue. – Jan Schatz Sep 03 '18 at 13:40
  • When i executed `rsync -rl --safe-links pi@:/{lib,usr} .`, i encountered an error:rsync: `send_files failed to open "/usr/lib/cups/backend/vnc": Permission denied (13)`. Have you checked if there were some errors before compile the SDK? – Michael Xu Sep 04 '18 at 09:32
  • Could please provide the detail error log when compiled the sdk? You can refer to a closed issue here(https://github.com/Azure/azure-iot-sdk-c/issues/96), maybe it is helpful for you. – Michael Xu Sep 05 '18 at 09:41
  • @michael-xu-msft, I don't have a Raspberry Pi. We are building our own Linux environment. Thus the sysroot is already on my development PC. – Jan Schatz Sep 14 '18 at 08:29

0 Answers0