Search code examples
ccross-compilingembedded-linuxazure-iot-hubazure-iot-sdk

Cross-compiling Azure IoT SDK for C


I have successfully managed to cross-compile the C Azure IoT SDK for a target device running embedded Linux. The instructions are here : https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/SDK_cross_compile_example.md

The next step is to get a basic application using the SDK running on the target device.

How would one go about doing this? Where are the generated libraries etc. to copy to the sysroot of the target device.

There seems to be only support for Rasberry Pi and generating a new firmware image.


Solution

  • I would recommend that you use the -DCMAKE_INSTALL_PREFIX=[output path] when you generate your makefiles. Once you have run cmake and make you can then run make install which will copy the generated libraries to the location you chose. You do NOT want to install them into your host's library search path since (presumably) they are built for an incompatible architecture. Having done that the /lib directory will have the libraries that you need to use to build your application. These are static libraries (unless you chose otherwise) so they only need to be linked to your application. They do not need to be on the device. Obviously you will also need to cross compile your application.

    There are a couple of things you need to look out for though. Your device will need to have the same version of OpenSSL and curl that you used when you built the SDK. These are dynamic libraries so your application would likely fail at run time if you don't take care of that since there would be a version mismatch.

    There is another example of cross-compiling here: https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/Docker_SDK_Cross_Compile.md. This version also builds the prerequisite libraries and has suggestions about how you might also cross compile your application. It uses a Docker container to do this but, even if you don't want to use Docker, it may still help you with your process.