Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Target Libraries on Host

I am trying to cross compile a C++ application for ARM64 using CMake. I have a working cross compiler and can compile hello world for ARM64 easily.

However, this particular application has a lot of dependencies, like libxml2.

Now, I can see this library has already been built for arm64 in the debian repos (https://packages.debian.org/buster/arm64/libxml2/download).

However, there doesn't seem to be an easy way to download it and its dependencies to a sysroot I could point the cross compiler to. It seems like I would have to manually download, extract, and place it in my sysroot.

Is there a way I can tell apt or apt-get to download and install the arm64 version of a package to a specific sysroot instead of installing it to my main directory?

How do other people accomplish this basic task?

like image 628
Gillespie Avatar asked May 25 '26 12:05

Gillespie


1 Answers

This is indeed a basic task. The problem is that apt-get defers to dpkg which defers to the path in the package. Neither understands sysroot's. There's a half-arsed attempt to support chroot, but of course a non-native sysroot cannot be a chroot.

However, if you look at the list of files in your package, you'll see that it installs to /usr/lib/aarch64-linux-gnu/. You can either copy the files from there to the sysroot, or use (like Docker) something like AUFS/OverlayFS to virtually merge these directories.

Given the "not designed to work" nature of this hack, it makes sense to keep the entire cross-compile setup in a Docker container of its own, so if you would overwrite some native libraries you just discard the container. This gets you that overlay functionality for free; Docker containers are already built from layers.

like image 91
MSalters Avatar answered May 27 '26 04:05

MSalters