Cross-compiling rust for x86_64-unknown-linux-musl target problems

Hi there, I tried compiling rust for the target above and while that worked, but compiling a simple hello world program failed with
= note: /home/user/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-c0a6a180cc46432e.rlib(alloc-c0a6a180cc46432e.2dnjn04rkze68zbm.rcgu.o): In functionalloc::al
loc::handle_alloc_error::h47bb1c69f57a0d07’:
2dnjn04rkze68zbm:(.text._ZN5alloc5alloc18handle_alloc_error17h47bb1c69f57a0d07E+0x3): undefined reference to rust_oom' collect2: error: ld returned 1 exit status

From my (rudimentary) investigation it seems that rust_oom is defined in libstd but libstd is linked before liballoc so the symbol is removed at link time.

When installing the target to the current stable/nightly toolchain everything works so the problem is most likely with the way I compiled rustc.

Any help would be appreciated!

Hi,

Hi, Did you figure out what the problem was? I have met the same issue

Maybe late, but I have good experiences with using docker alpine image with musl - I was able to build things statically , that I was struggling to build in my normal environment. Default target there is x86_64-alpine-linux-musl, which links dynamically, but this env var will force fully static build RUSTFLAGS="-C target-feature=+crt-static"

1 Like

Another option is building in Docker with clux/muslrust or ekidd/rust-musl-builder. The benefit here is that these bring in some pre-built dependencies like OpenSSL.