Anthony J. Martinez

Cross-Compiling with Debian Multiarch

About a year ago, I created a project to keep notes on how I cross-compiled one of my Rust crates for some legacy systems on both ARMv7 and i686. At the time it was sufficient to statically link the entire C-runtime into these binaries. I left it at that and continued along my merry way without a care in the world for cross-compilation of any higher complexity.

Fast-forward to a few weeks ago, and I again had need for cross-compilation of a Rust binary at work towards an ARMv7 target with a dependency on the target system's libpcap. Time and time again my attempts, based on my original experiences with cross-compiling Rust for ARMv7, were met with frustrating failure. The linker could not find lpcap.

My searching of the vast series of tubes did not bring me any direct joy, often with some critical steps missing, but a distant memory reminded me of deb --add-architecture. This was the magic I sought, and if you seek to do similar work the finer points follow:

  1. If you have dependencies on libraries that differ between architectures, as many do, then a Debian based system may help you get those headers your crossbuild toolchain needs
  2. Use dpkg --add-architecture <TARGET_ARCH> to add your target architecture
  3. Run apt update to get the list of available packages for that target.
  4. Once you know which libraries you depend on, make note of the specific version present in your release. libpcap-dev itself has no armhf installation candidate, but apt search libpcap-dev will show you that libpcap0.8-dev (in Debian Stretch) is the package you really want and it does have an installation candidate.
  5. Continuing the libpcap-dev example, run apt -y install libpcap0.8-dev:armhf to install development headers specific to the armhf architecture.

Doing this has saved quite a bit of time as I can now compile on a much more powerful system than the embedded industrial PC that is my actual target (or the Beaglebone Black that has the same processor).