Reputation: 16607
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?
Upvotes: 9
Views: 10550
Reputation: 119
If you want a simple way of doing it, try the cross project. It requires Docker, but is super easy.
cargo install cross --git https://github.com/cross-rs/cross
Make sure your user can run Docker:
sudo usermod -aG docker ${USER}
Then, for example, if you want to compile for armv6l arch:
cross build --target arm-unknown-linux-gnueabihf --release
If you want to compile for armv7l:
cross build --target armv7-unknown-linux-gnueabihf --release
The compiled file will be placed in the usual target/armv7-unknown-linux-gnueabihf/release/... folder.
Make sure to check the proper destination arch in the targeted system with the command arch. Example:
pi@raspberrypi:~ $ arch
armv6l
Upvotes: 1
Reputation: 16607
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.:
* 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.
Upvotes: 9