How to build against libiio (IIO libraries) for arm64 (aarch64)?

Hi. I’m trying to build a test application for an adc, using IIO. I’m not sure if the way I’m building is up to date, as I’m doing it with a container and not with torizoncore-builder.
I have the following Dockerfile:

ARG CROSS_TC_IMAGE_ARCH=armhf
ARG CROSS_TC_DOCKER_REGISTRY=torizon
ARG BASE_NAME=debian
ARG IMAGE_ARCH=linux/arm/v7
ARG IMAGE_TAG=2-bullseye
ARG DOCKER_REGISTRY=torizon

# First stage, x86_64 build container
FROM $CROSS_TC_DOCKER_REGISTRY/debian-cross-toolchain-$CROSS_TC_IMAGE_ARCH:$IMAGE_TAG AS cross-container
ARG GCC_PREFIX=arm-linux-gnueabihf

# copy project source
WORKDIR /project
COPY src/ /project

# compile
RUN mkdir build \
    && cd build \
    && $GCC_PREFIX-gcc -Wall -D_GNU_SOURCE -Og -o test ../test.c -liio

# Second stage, container for target
FROM --platform=$IMAGE_ARCH $DOCKER_REGISTRY/$BASE_NAME:$IMAGE_TAG AS deploy-container

# get the compiled program from the Build stage
COPY --from=cross-container /project/build/* /usr/local/bin/

CMD ["test"]

And then I build the image with running:

$ docker build . --build-arg CROSS_TC_IMAGE_ARCH=arm64 --build-arg IMAGE_ARCH=linux/arm64 --build-arg GCC_PREFIX=aarch64-linux-gnu -t test

Build stage fails because the linker does not find iio:

/usr/lib/gcc-cross/aarch64-linux-gnu/10/../../../../aarch64-linux-gnu/bin/ld: cannot find -liio
collect2: error: ld returned 1 exit status

Of course, I could apt install libiio0 inside the container, but that installs the amd64 binaries.
Now, a bunch of questions:

  1. Do I have to compile the iio library inside the container to build the test image?
  2. Isn’t there any precompiled library to install or another image to use?
  3. Does the torizon image running on my board have the binaries of the iio library?

Greetings @pato,

I feel most of your questions here would be clarified by taking a look at this article here: How to do C/C++ Development on Torizon

Do I have to compile the iio library inside the container to build the test image?

Any library needed for your application to compile and run needs to be in the corresponding container.

Isn’t there any precompiled library to install or another image to use?

The Debian package manager should. As shown in the article I linked you should be able to specify what architecture of this package you want to install.

Does the torizon image running on my board have the binaries of the iio library?

I don’t believe so and even if it did the container doesn’t have access to the libraries outside on the host.

Best Regards,
Jeremias