2

I compile a Rust binary on one Linux system and try to run it on another. When I run the program I get:

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

GLIBC aka libc6 is installed on the system, however, the version is 2.31 Is there a way to compile the program for a less recent version of libc6?

Maciej Krawczyk
  • 12,119
  • 5
  • 42
  • 54

1 Answers1

3

Per the issue: https://github.com/rust-lang/rust/issues/57497 - there's no way to tell the Rust compiler to link a different library other than the one installed on the system.

This means I have to compile the binary on a system that has a less recent version of libc6 installed - then the binary should be compatible with the same version of libc6, or a more recent version*

The most convenient way of doing that would by using a Docker image that has the target libc6 version and rustup.

For myself, the official Rust docker image had the correct version I could use to compile for my target.

In the working directory:

sudo docker pull rust
sudo docker run --rm --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/myapp -w /usr/src/myapp rust cargo build --release

If the official image, which is based on Debian does not satisfy the version requirement, you will have to create a custom docker image, i.e.:

  • fork the official Rust docker image and set it to use an older version of Debian
  • or create an image that is based on an older Debian or other Linux distro image and configure it to install rustup

* I could use a binary compiled with libc6 2.31 on a system that has libc6 2.32 - I'm not sure how far backwards compatibility goes.

Maciej Krawczyk
  • 12,119
  • 5
  • 42
  • 54