Cross compilation issue with YOCTO/meta-rust

I know this is maybe a bit niche for the forum, but I've been head-butting this specific issue for two days now without any perceivable progress.

I want to build a cross-compiled application for a Pi 4 target, aarch64. As I use YOCTO to build the full Linux system, this is part of the YOCTO recipes (declarations of software to build and install on an embedded system).

Rust support for my version of YOCTO (Dunfell) comes via meta-rust, a so-called layer that adds a full build of cargo and toolchain to the host tools. And SDK, which is the YOCTO speak for a bundle of both system libraries, includes, cross-compilation tools that you can install, and use to build target applications. This is what I want to use for ease of workflow - fully compiling the application + creating the image for just one code line change is not that great, and also errors / build issues are stowed away into logfiles. So not an acceptable workflow.

Building my application within YOCTO works fine (YOCTO then uses the host tools deep from within its bowels, e.g. cargo is $HOME/company-os/build-rpi4-product/tmp-glibc/work/aarch64-oe-linux/product-display-server/1.0-r0/recipe-sysroot-native/usr/bin/cargo

But when using the SDK, I get the following:

$cargo build --release
                               Downloaded anyhow v1.0.70
  Downloaded 1 crate (43.8 KB) in 0.33s
   Compiling anyhow v1.0.70
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/tmp/rustcRn1UGP/symbols.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.0.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.1.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.10.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.11.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.12.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.13.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.14.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.15.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.2.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.3.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.4.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.5.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.6.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.7.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.8.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.build_script_build.6f502208-cgu.9.rcgu.o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560.3rir2k40e5hvhmhx.rcgu.o" "-Wl,--as-needed" "-L" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/deps" "-L" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libstd-424ed5310f9d0ce4.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-e217fe2b3e9b26e5.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libobject-e5ba0dbcaefdcd77.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-1e5c229d1f08b5fa.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-55513b7d5ebf54d4.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-7b834b5d7976e08f.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-1d6148a20bf951f5.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-6c4d936200910a2a.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-eb739aecaa57c793.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-110becf2eea9701a.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-00bfa21ba5f0d53c.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libadler-b7c6d886604d6585.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-d0a487c946f930f5.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-00b53933df44234e.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-a723cb1c8c8a4ebd.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-34d63b48300b1c84.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-d7fc054418764dd1.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-76f3fdfd13d0bf64.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libcore-01897717fa76a34d.rlib" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-0965c46034bf6b32.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/opt/aos-aarch64/sysroots/x86_64-oesdk-linux/usr/lib/aarch64-oe-linux/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/dir/projects/company/company-os/layers/meta-company-product/recipes-support/product-display-server/product-display-server/target/release/build/anyhow-d6862c2d8addf560/build_script_build-d6862c2d8addf560" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: cc: fatal error: '-fuse-linker-plugin', but liblto_plugin.so not found
          compilation terminated.

The cc in question here seems not to be the SDKs GCC 9.3, located somewhere under /opt/aos-aarch64 (the SDK toplevel), but instead /usr/bin/cc on my host system ("Ubuntu 22.04.1 LTS"). This might be a difference to running cargo (and subsequently rustc) from "within" YOCTO. I tried figuring that out by inspecting the environment in both instances, but to no avail.

Any pointers or ideas to unblock me are very welcome, and again sorry for the somewhat tangential topic.

I also am aware of meta-rust-bin, somehow same issue.

Ohhhhkeeey. I decided to ditch the cross-compilation and targeting the Pi to make some progress on my general project that's about IPC with memory mapping on Linux - once the cross compilation works, this would still hold.

And I can't compile the project for x86 either. Exact same error. So something seems to be awry with my system in general :confused:

Update: after linking /usr/bin/cc to sudo ln -s $(which gcc-12) /usr/bin/cc things work. Huh.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.