Post Go back to editing

Error in compiling program using libad9361 and libiio

Category: Software
Product Number: libiio and libad9361
Software Version: libiio- v0.25 and libad9361 latest master branch

I am trying to compile a simple sdr program (pluto_sdr_program.c)

Getting below error:

I did a fresh clone, make and make install of libiio and libad9361( you can see libad9361 and libiio folders in above screen shot)

I followed this link

 Installing libad9361 from source 

did a git clone of libiio 

git checkout v0.25

did a cmake make make install

abh@abh-VirtualBox:~/Downloads/test_sdr$ ls -l /usr/lib/x86_64-linux-gnu/*iio*
lrwxrwxrwx 1 root root 11 Nov 25 10:42 /usr/lib/x86_64-linux-gnu/ ->
lrwxrwxrwx 1 root root 14 Nov 25 10:42 /usr/lib/x86_64-linux-gnu/ ->
-rw-r--r-- 1 root root 655112 Nov 25 10:42 /usr/lib/x86_64-linux-gnu/

iio_info command works. ( below image)

libad9361 compile & install is successful

Verified the installed .so in 

#include <stdio.h>
#include <stdlib.h>
#include <iio.h>

// Define the desired parameters
#define RX_LO_FREQ 915000000UL   // 915 MHz
#define TX_LO_FREQ 915000000UL   // 915 MHz
#define SAMPLING_RATE 3200000UL  // 3.2 MSPS
#define RX_GAIN 50               // Example RX gain in dB
#define TX_GAIN 50               // Example TX gain in dB

void loop(struct iio_buffer *rx_buffer, struct iio_channel *rx_chan);

int main() {
    struct iio_context *ctx;
    struct iio_device *rx_dev, *tx_dev;
    struct iio_channel *rx_chan, *tx_chan;

    // Initialize the IIO library
    //ctx = iio_create_default_context();
	ctx = iio_create_network_context("");

    if (!ctx) {
        fprintf(stderr, "No context\n");
        return -1;

    // Connect to RX and TX devices
    rx_dev = iio_context_find_device(ctx, "ad9361-phy");
    tx_dev = iio_context_find_device(ctx, "ad9361-phy");

    if (!rx_dev || !tx_dev) {
        fprintf(stderr, "No device found\n");
        return -1;

    // Configure RX LO frequency
    rx_chan = iio_device_find_channel(rx_dev, "altvoltage0", true);
    if (!rx_chan) {
        fprintf(stderr, "Cannot find RX LO channel\n");
        return -1;
    iio_channel_attr_write_longlong(rx_chan, "frequency", RX_LO_FREQ);

    // Configure TX LO frequency
    tx_chan = iio_device_find_channel(tx_dev, "altvoltage1", true);
    if (!tx_chan) {
        fprintf(stderr, "Cannot find TX LO channel\n");
        return -1;
    iio_channel_attr_write_longlong(tx_chan, "frequency", TX_LO_FREQ);

    // Configure sampling rate and gain for RX
    struct iio_channel *rx_samp_chan = iio_device_find_channel(rx_dev, "voltage0", false);
    if (!rx_samp_chan) {
        fprintf(stderr, "Cannot find RX sample channel\n");
        return -1;
    iio_channel_attr_write_longlong(rx_samp_chan, "sampling_frequency", SAMPLING_RATE);
    iio_channel_attr_write_int(rx_samp_chan, "gain_control_mode", 0); // Set to manual gain control mode
    iio_channel_attr_write_int(rx_samp_chan, "hardwaregain", RX_GAIN);

    // Configure sampling rate and gain for TX
    struct iio_channel *tx_samp_chan = iio_device_find_channel(tx_dev, "voltage0", true);
    if (!tx_samp_chan) {
        fprintf(stderr, "Cannot find TX sample channel\n");
        return -1;
    iio_channel_attr_write_longlong(tx_samp_chan, "sampling_frequency", SAMPLING_RATE);
    iio_channel_attr_write_int(tx_samp_chan, "hardwaregain", TX_GAIN);

// Define buffer sizes (number of samples)
#define RX_BUFFER_SIZE 1024  // Example size
#define TX_BUFFER_SIZE 1024  // Example size

// Create and configure RX and TX buffers
struct iio_buffer *rx_buffer;
struct iio_buffer *tx_buffer;

rx_buffer = iio_device_create_buffer(rx_dev, RX_BUFFER_SIZE, false);
if (!rx_buffer) {
    fprintf(stderr, "Could not create RX buffer\n");
    return -1;

tx_buffer = iio_device_create_buffer(tx_dev, TX_BUFFER_SIZE, true);
if (!tx_buffer) {
    fprintf(stderr, "Could not create TX buffer\n");
    return -1;
// set blocking mode for both rx and tx buffers
iio_buffer_set_blocking_mode(rx_buffer, true); // Set RX buffer to blocking mode
iio_buffer_set_blocking_mode(tx_buffer, true); // Set TX buffer to blocking mode


// Clean up

 // Cleanup
    return 0;

void loop(struct iio_buffer *rx_buffer, struct iio_channel *rx_chan)
	// Streaming loop (example for RX)
while (1) {
    // Refill RX buffer
    ssize_t nbytes_rx = iio_buffer_refill(rx_buffer);
    if (nbytes_rx < 0) {
        printf("\n No i,q samples in iio buffer\n");

    // Process RX data
    const char *rx_data = iio_buffer_first(rx_buffer, rx_chan);
    // Process 'nbytes_rx' bytes of data starting at 'rx_data'

    // Example: Read and process samples
    for (ssize_t i = 0; i < nbytes_rx / sizeof(int16_t); i += 2) {
        int16_t i_sample = ((int16_t *)rx_data)[i];   // I sample
        int16_t q_sample = ((int16_t *)rx_data)[i+1]; // Q sample
        // Process (I, Q) samples
		float i_sample_float = (float)i_sample / 2048.0f;
		float q_sample_float = (float)q_sample / 2048.0f;



  • The problem is resolved, 

    Steps 1. issue was due to multiple version of libiio present.  rm -rf *iio* in /usr/lib/x86_64-linux-gnu/

    git clone and checkout v0.25 

    mkdir build; cd build

    cmake ..


    sudo make install

    sudo ldconfig

    after this run iio_info : if this command runs then libiio is installed successfully.

    Output is some thing like this:

    abh@abh-VirtualBox:~/Downloads/test_sdr$ iio_info
    iio_info version: 0.25 (git tag:b6028fde)
    Libiio version: 0.25 (git tag: b6028fd) backends: local xml ip usb
    IIO context created with local backend.
    Backend version: 0.25 (git tag: b6028fd)
    Backend description string: Linux abh-VirtualBox 5.15.0-89-generic #99~20.04.1-Ubuntu SMP Thu Nov 2 15:16:47 UTC 2023 x86_64
    IIO context has 2 attributes:
    local,kernel: 5.15.0-89-generic
    uri: local:
    IIO context has 2 devices:
    hwmon0: AC
    0 channels found:
    No trigger on this device
    hwmon1: BAT0
    1 channels found:
    in0: (input)
    1 channel-specific attributes found:
    attr 0: input value: 10000
    No trigger on this device

    Step2 Proceed with libad9361 installation (i took the latest version) (no need to create a build folder, 

    cmake .


    sudo make install

    sudo ldconfig


    then compile ad9361-iiostream.c

    gcc -o pluto ad9361-iiostream.c -liio -lad9361

    if you code compiles then everything is fine.

    ./pluto or ./pluto ip: