Post Go back to editing

How do I build simple application that uses libiio?

Category: Software
Product Number: adrv9364
Software Version: petalinux 2019.1

Hi all, 

I have an Ubuntu machine with petalinux 2019.1 installed and I managed to build a simple user application which does not use libiio (main.c that just prints hello world to stdout), and I managed to run this application on adrv9364's zynq processor
(meaning - I used the petalinux build system to build an image [BOOT.bin etc.] which contains that simple application).

When I tried to change that simple application to use libiio (include the iio.h header file for example) I've got an error that says "iio.h file not found" in  the build process . 

In order to solve this I tried to cross-compile libiio (from source I've cloned from git) but I failed (too many problems like missing LIBXML2 etc that I failed to solve too.). 

So now, as I understand that cross compiling to zynq's arm is a very hard task, I want to ask two questions that might help me: 

1. How do I make the petalinux build system to recognize/be aware of the libiio library? Is it even possible ?
2. How do I build such an application [that uses libiio] on the target device [ZYNQ's arm in my case]? I tried to find the answer here but it does not really explain how to do so....

My goal is to build a simple application like ad9361-iiostream.c [from libiio examples] and run it directly on the zynq device [meaning - using the local backend, I don't want it to run on host PC and use network/usb backend]

thanks a lot for your help here 

  • 1. PetaLinux itself is based off Yocto Linux, which itself uses a layering process to construct a custom image with integrated libraries. So if you want a new library, it should be built into a Yocto/Peta layer. ADI provides a common layer set which does have libiio support:

    2. Once you have a built PetaLinux image with libiio built into it, you can cross-compile against its sysroot to build applications for that architecture and library set. The sysroot should be a artifact generated from the build process. However, you will likely need to ask Xilinx where it gets placed.

    I will also mention an alternative. If you leverage Kuiper Linux (the ADI Linux distribution for Zynq+Intel+RPI) it comes with libiio installed and compilers. Therefore, you can just build on the system itself:


  • Thanks for your quick reply Travis, 

    I tried 1+2 but I failed in the cross-compile stage.

    Regarding 3 - Sounds interesting, I want to try this, but as I understand - Kuiper Linux and Petalinux (the linux image that is built using petalinux build system) are different, right ? 

    To explain my question - I want to build a new custom BOOT.bin file (which is based on a custom system.bit file that I generate from Vivado) and deploy it to Zynq - if I build the BOOT.bin using Petalinux build system - will it run with Kuiper Linux without any problem? 

  • So PetaLinux is really independent of the bitstream creation. So generally yes you can use the generated bitstreams with Kuiper. This typically will require packaging the bistream into a BOOT.BIN. Here is the process:


  • Travis, thanks again for your help, I finally managed to build an application that uses the libiio library and run it on the Zynq processor , I'm writing the steps here so everyone else, who might face the challenges I met, can use and solve them: 

    1. I have one SD card that was flashed with your pure Kuiper Linux image.
    2. I have other SD card with Petalinux image that I built using the Petalinux build system (I use it to build and package custom FPGA bit streams that I create and compile custom Device Tree files [I need to make changes to both bit stream and device tree]) .

    I use the SD from 2 in production.
    When I want to build libiio application I use the SD from 1 and run the following in order to compile the application: 

    gcc my_app.c -o my_app -I/usr/include/ -L/usr/local/src/libiio/build/ -liio

    I had to use -I (capital i) to indicate the path where iio.h file is located, -L to indicate where the file is located and -liio to tell the compiler to link with libiio. 

    When my_app file was created I copied it to the SD card from 2 and run it there.

    So bottom line is - I still have the power of Petalinux for building and packaging the image (no need to setup a new environment from scratch for Kuiper), and I use the Kuiper image for "cross-compiling" the application.