简体   繁体   English

使用外部库交叉编译 C 代码

[英]cross compiling C code with external libraries

Host system: x86-64 Linux, Ubuntu 20.04主机系统:x86-64 Linux、Ubuntu 20.04

Target system: aarch64 Linux, Debian 11, arm architecture: Cortex A53目标系统:aarch64 Linux、Debian 11、arm 架构:Cortex A53

I develop for an aarch64 based Linux system on matlab/simulink.我在 matlab/simulink 上开发基于 aarch64 的 Linux 系统。 This toolchain is currently worked out for Linux and Windows hosts.该工具链目前针对 Linux 和 Windows 主机制定。 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.然而,由于系统上有额外的 IIO 设备,很明显当前仅对 IIO 设备编号进行硬编码的方法不再有效。

Now I found libiio which works great when I compile simple programs on the target itself.现在我发现libiio在目标本身上编译简单程序时效果很好。 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:我一直在尝试通过制作交叉编译文件来交叉编译libiio库本身:

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.当我从我在libiio文件夹中创建的构建文件夹运行cmake../ -DCMAKE_TOOLCHAIN_FILE=~/development/crosscomp.cmake crosscomp.cmake 时,它似乎工作正常。 But when I run make the issue starts.但是当我运行 make 时,问题就开始了。

[ 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.我收到此错误,我确实安装了 libavahi-common-dev 和 libavahi-client-dev。

But I think it wants aarch64 compiled versions of the dependencies.但我认为它需要依赖项的 aarch64 编译版本。 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.我尝试从目标中获取 .so 文件,但它会抱怨缺少一堆其他依赖项。 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.即便如此,我也只能设法从 Linux 主机构建,从 Windows 主机构建感觉需要更多的麻烦,但我可能是错的。 I'm still learning a lot about how all this works.我仍然在学习很多关于这一切是如何运作的。

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.我大部分时间都在使用它,我在我的 ARM 系统上本地编译了库,但我删除了一堆我不需要的功能。 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.这给我留下了一个没有任何外部依赖项的库(如前面提到的 avahi common/client 和更多),然后在我的 makefile 中引用它并包含 header 文件使其工作。

Was also able to cross compile from my x86 based host.也能够从我的基于 x86 的主机交叉编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM