How to fix library dependency checking for cross-builds

Snapcraft uses “ldd” to check library dependencies.
This is not working for cross-builds (building will give lots of “Unable to determine library dependencies” warnings).

Here is how to solve this:

  1. Make ldd “cross-capable” (only a few simple modifications required, see attached example for armhf)
  2. Force snapcraft to use your new “cross-ldd”. I did this by symlinking it to /usr/local/bin/ldd, but there might be better solutions (that don’t override your host-ldd).
  3. Add build dependency on qemu-user-static (which does the heavy lifting in getting ldd “cross-capable”)

How it works:
ldd is just a script that calls the system linker/loader (ld*.so).
We just need to change its list of eligible linker/loaders to include the target-platform ones, and then use QEMU for the call. By relying on binfmt, it is even possible to completely emit qemu from the cross-ldd file, but this does not work inside LXC containers.

arm-linux-gnueabihf-ldd: https://pastebin.com/LDgZaE7K

1 Like

Thanks a lot for the post. I have used your solution to build a snap package for armv7 inside a default snapcraft docker (snapcore/snapcraft:core) built for amd64, so step 2 using the symlinking suited me very well.