Compile a static binary for deployment on cluster

The issue isn’t exactly the location of libc, but rather the version of libc that the binary requires. There are a couple of approaches here.

You can compile your binary on a system with a sufficiently old version of libc - I like to use Docker for this personally.

It’s unfortunately not really possible to statically link to glibc in a reasonable way. If you do want a completely static binary, another option is to use the x86_64-unknown-linux-musl target, which uses musl as its libc instead of glibc and can be statically linked. I believe all you’ll have to do in this case is install musl, install a copy of the standard library built for that target (available here) and then specify that target when you build: cargo build --target x86_64-unknown-linux-musl. I haven’t actually tried this myself, though.

1 Like