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
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
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:
- 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
dpkg --add-architecture <TARGET_ARCH>to add your target architecture
apt updateto get the list of available packages for that target.
- Once you know which libraries you depend on, make note of the specific version
present in your release.
libpcap-devitself has no
armhfinstallation candidate, but
apt search libpcap-devwill show you that
libpcap0.8-dev(in Debian Stretch) is the package you really want and it does have an installation candidate.
- Continuing the
apt -y install libpcap0.8-dev:armhfto install development headers specific to the
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).