Cross-compiling Azure IoT SDK for C - 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.

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.

Related

How to automatically find or build C library dependencies on Windows/MSVC?

I have a tool in C that needs libpng, zlib and lcms libraries. On unix I get these dependencies via pkg-config, but on Windows I can't rely on it, so for users building the library it's a massive hassle to obtain and build these dependencies manually.
How can I automate obtaining these dependencies in the most Windows-native way? I know MinGW helps, but that's a bit of a cop-out. I'd like to learn how to do it with the Microsoft toolchain.
Is there any point in searching for shared non-Microsoft libraries on Windows, or should I go straight for statically linking my own?
If I were to download and build the libraries as part of my build script, what should I use? (nuget? curl? ftp.exe?)
It seems like Microsoft is discouraging use of NuGet for C? https://github.com/Microsoft/vcpkg/blob/master/docs/about/faq.md#why-not-nuget
I recommend looking into Nuget. It's fast becoming the Microsoft standard for these sort of things. A lot of people think Nuget is just for .NET, but it works great for VC++ too. I have had a great deal of success setting up Nuget servers in my company to serve headers and compiled libs, and I've gotten all of our automated build systems to create these things automatically. I'm not going to spell out all the details here, but it basically comes down to performing your build, creating an MSBuild XML snippet to set up the precompiler and link options automatically, and then packaging all those bits (headers, libs, XML) in the correct way. When done correctly, it's just a two step process to use an existing package in a new project -- establish the Nuget reference and then add the #includes into your code. You don't even need a server -- you can source them directly from a directory of your own control.
https://learn.microsoft.com/en-us/nuget/create-packages/native-packages

Use Azure IoT Plugin for C within Eclipse

Very new to C, Eclipse, and basically everything else I am trying to work with in this project. I have an Arduino Feather HUZZAH (ESP8266). I have flashed the firmware with the esp_iot_sdk and installed Eclipse on to machine through the unofficial Espressif Dev Kit in order to write the code for the board.
The code I wrote is working well but now I need to find a way to send the collected data to Azure's IoT Hub. I found this plugin for talking to the Azure IoT Hub but cannot figure out how in the world to get it installed using Eclipse.
Even if someone could show me how to get a simple POST request going in C, using a library or not, that would be awesome! Thanks for your help.
So you want to run azure-iot-sdk on ESP8266 with Tensilica Xtensa LX106 MCU.
The first thing you need to do is to port azure-iot-sdk C library to Xtensa platform, using the Espressif Dev Kit toolchain.
Normally, this is officially done by Microsoft. Unfortunately, Xtensa LX106 might not be on the list(roadmap?) yet.
So I think you can do some porting work yourself, following some tutorials from Microsoft. This link works for Linux host, but given that fact that Xtensa toolchain only supports windows for now, you might end up writing some cmd, bat or generic makefile/cmake file, in which you need to have the cross-compile toolchain(aka xtensa-lx106-elf-gcc) specified.
Hopefully, it's not complicated or cumbersome.
After you have done with this, you need some static or dynamic library assembly depending on your settings, the next step is to specify the library path in your eclipse project, and don't forget to include the azure-iot-sdk header folder to your project, as the snapshot shows.
You should be good to go after the above steps.

in-Built linux application with the kernel image or boot.img

how to make an application in built(like top, vi , etc ) so that they can be put inside the /system/bin automatically on flashing the kernel and can be accessed from the command prompt.
I tried modifying the Makefile for the my application by looking at the example of top utility but could not find it under /system/bin .
I am not sure if I have included the sources of the file in the Makefile correctly.
You need to start with something that the manufacturer provided. Presumably it's a devKit or something. Most modern dev kits ship with either a MFG provided development environment, kernel, sources, etc. Many are based on Yocto Linux.
You can't just compile a binary locally on your PC with whatever version of GCC you have and have it work on an embedded environment. Chances are it's a different architecture (ARM or Freescale or something). There are ways to cross-compile but is some setup involved. Read about cross compiling here: http://en.wikipedia.org/wiki/Cross_compiler
There are development and packaging environments that have been developed by the community but it's not for the faint of heart. In short, start reading: https://www.yoctoproject.org/

Cross compiling with existing rootfs and external toolchain (buildroot? qemu?)

I am working on an arm embedded platform based on the Cortex A9, very similar to the hummingboard (http://www.solid-run.com/products/hummingboard/).
I am working on porting over some of our software that was previously running on a beaglebone. Our software is python based but uses some ctypes, an internal c library as well as several python modules and a rabbitmq server. On the beaglebone, setting this up was easy because there is a lot of support and ubuntu based distros that make it simple to install packages.
I have a linaro cross compiler and a uboot and rootfs image given to us by the manufacturer of the platform. Manually cross compiling and building all of our necessary dependencies is turning into quite a headache, as everything has little quirks. I do not have a native development toolchain that can run on the arm device.
I am looking for a simpler way to do some of these tasks. Buildroot sounds like exactly what I need, but I am not sure how I would make it work with an already existing rootfs and toolchain. Unfortunately, I don't know all the details of the rootfs and how the hardware is brought up, so I don't think I can replicate the settings exactly using buildroot.
Another option I was looking into was somehow using the rootfs with QEMU and building a native toolchain to run on it, which would allow me to manually build the dependencies without needing to deal with the headaches of cross compiling.
Any help is very much appreciated. Thanks.
Buildroot is designed to generate an entire rootfs, not to "complement" an existing one. So if you were to use Buildroot, you should get rid of the existing root filesystem, and use the new one generated by Buildroot.
Also, note that if you were happy with the Debian distro running on your BeagleBone, you can also run Debian on your Hummingboard.

Auto packgaing for applications in linux

It's my first time to try to get a distributed version of an application, I have a simple C application that uses GTK3 lib , when i compile this application and try to run the executable file on another Linux system that hasn't GTK lib installed of course it doesn't work !!
Is there a known and easy packaging method to get an executable file that works fine when distributed ?
Or i need to make my application installs needed libs to work and if so what is the best way to do this too ?
Note: i don't need a cross platform solution, i just want to run the application on another Linux system that hasn't GTK lib installed
In short: either you build in static or you do a package with the required dependencies.
The second solution is what I would recommend. You don't need to depend on the development files but only the library. Have a look to the documentation of your distribution in order to understand how to build a package.

Resources