ccmakecross-compilingiio

cross compiling C code with external libraries


Host system: x86-64 Linux, Ubuntu 20.04

Target system: aarch64 Linux, Debian 11, arm architecture: Cortex A53

I develop for an aarch64 based Linux system on matlab/simulink. This toolchain is currently worked out for Linux and Windows hosts. However due to additional IIO devices on the system it has become clear that the current approach of just hardcoding the IIO device numbers is not gonna work anymore.

Now I found libiio which works great when I compile simple programs on the target itself. However I have not managed to cross compile applications using the library.

I have been trying to cross compile the libiio library itself by making a cross compilation file:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_STAGING_PREFIX /home/maud/development/stage)

set(tools /usr/aarch64-none-linux-gnu)
set(CMAKE_C_COMPILER ${tools}/bin/aarch64-none-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/aarch64-none-linux-gnu-g++)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

when I run cmake ../ -DCMAKE_TOOLCHAIN_FILE=~/development/crosscomp.cmake from the build folder that I made in the libiio folder it seems to work fine. But when I run make the issue starts.

[ 28%] Building C object CMakeFiles/iio.dir/dns_sd_avahi.c.o
Reaping winning child 0x55c895073d40 PID 36856 
Live child 0x55c895073d40 (CMakeFiles/iio.dir/dns_sd_avahi.c.o) PID 36858 
/home/maud/Downloads/libiio-master/dns_sd_avahi.c:24:10: fatal error: avahi-common/address.h: No such file or directory
   24 | #include <avahi-common/address.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~

I get this error, I do have libavahi-common-dev and libavahi-client-dev installed.

But I think it wants aarch64 compiled versions of the dependencies. And it makes me question whether this is even a feasible goal, whether what I'm doing is even going to get me to where I want to be.

Is it even possible to add a library like this to such a cross compiling toolchain?

I tried taking the .so file from the target, but it will complain about missing a bunch of other dependencies. And even then I will only have managed to build from a Linux host, building from a Windows host feels like it would require way more trouble but I could be wrong. I'm still learning a lot about how all this works.


Solution

  • I got it mostly working, I compiled the library localy on my ARM system, but I tore out a bunch of features that I didnt need anyway. this left me with a library that didnt have any external dependencies (like the previously mentioned avahi common/client and a bunch more), then referencing it in my makefile and inluding the the header file got it working.

    Was also able to cross compile from my x86 based host.