Cross compile for aarch64-unknown-linux-gnu on Windows

I want to cross compile target for aarch64-unknown-linux-gnu on my Windows. I added following lines in .corgo/config.toml. When I build with cargo build --target=aarch64-unknown-linux-gnu --release, I got errors:

 rust-lld: error: unable to find library -lgcc_s
          rust-lld: error: unable to find library -lutil
          rust-lld: error: unable to find library -lrt
          rust-lld: error: unable to find library -lpthread
          rust-lld: error: unable to find library -lm
          rust-lld: error: unable to find library -ldl
          rust-lld: error: unable to find library -lc

My config.toml file:

[target.aarch64-unknown-linux-gnu]
linker = "rust-lld"

Thanks for the help.

Using just lld as linker is not enough. To compile for linux you need the gcc or clang wrapper around the linker to tell the linker which libraries it needs to link against and where to find them. In addition you need libc locally. You could try getting a cross-compilation gcc that runs on windows and compiles to linux. You could also try using zig cc as linker: Zig Makes Rust Cross-compilation Just Work ยท Um, actually...

2 Likes

In my experience this works fine if you have run rustup target add [target-name] (which it looks like you have?) and you have no non-rust code to compile or native libraries to link, otherwise you're at the mercy of the native toolchain and the dependencies it has - I might be missing something here though!

This might be less of a problem in the mid to long term, as the raw-dylib RFC seems to be getting close, which as I understand it is the first of several steps to removing the need for import libraries to cross compile.

libstd links against libc, which is a native library.

My understanding is the target ships with the standard rust libraries already built and satisfying the linker?

rustup target add aarch64-unknown-linux-gnu is not enough.

Cross compiling to linux on windows is not a good choice. just as bjorn3's reply, if you configure your system correctly, rust-lld will work well.

I also recommend to use zig cc as linker for cross-compilation. cargo-zigbuild is a crate which can compile cargo project with zig as linker for easier cross compiling.

2 Likes

libstd(of aarch64-unknown-linux-gnu) dynamicly link to libc. If you use cargo build --target x86_64-unknown-linux-musl(or maybe aarch64-unknown-linux-musl ?), it just works.

But performance of musl libc's malloc is poor, it's not suitable for high-load application.

1 Like

Thanks for the detail, I commonly target musl, so that's good to know.

@c00t @bjorn3 Thanks for your help. I installed ziglang and try cargo zigbuild --target=aarch64-unknown-linux-gnu and it works now!

Thanks!