Cross compiling for platforms with older versions of glibc

So I'm working on learning both rust and how to use the piston game engine and I wanted to show my friend what I had done with out him needing to install the rust toolchain.

Fortunately we are both running linux and I ran cargo build --release and sent him the compiled binary file and the other assets he needed to run the program.

The issue that we then ran into is that he has an older version of glibc. Below is the message from stderr.

./hello_world: /lib/x86_64-linux/libc.so.6: version `GLIBC_2.32` not found (
required by ./hello_world)

I've tried using compiler flags when in my main.rs to force static linking during compilation, but I think the other crates are not statically linking their dependencies.

Is there a way to conveniently statically link all required external libraries so that I can create an easily distributable binary?

The linux-gnu targets imply using glibc, and static linking isn't well supported. Use a linux-musl target if you want a truly static binary.

To get a working binary linked with older glibc, you could try building in a container of the older OS.

Thanks for the reply. I'm having issues actually compiling using x86_64-unknown-linux-musl. I have installed the target using rustup and using my Manjaro's package manager pamac I've installed the musl libraries. However, when I go to compile I get on error time figuring out how to solve.

The error is too long for this forum so here is a link to it on pastebin

Any thoughts? Please let me know if I should provide any additional information.

I'm not sure, but there are a number of *-sys crates in your build which would have to be static as well, which may or may not be feasible. The actual error comes from trying to link libdl.so in a static build, but at a glance I can't tell for sure what added that. ("-Wl,-Bdynamic" "-ldl" "-ldl" "-ldl" "-ldl")

Not sure if this is really helpful, but some things have features that allow static linking.
I once fixed a cross compiling issue by explicitely importing the openssl crate and enabling it's vendored feature, and forced reqwest to use the rustls-tls feature etc to reduce these C dependencies. Maybe see if the things causing you issues have options like this.