Rust Linux version glibc not found - compile for different glibc / libc6 version - linux

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?

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.

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

Related

google-closure-compiler in node container gives libc.so.6: version GLIBC_2.32 not found

This used to work just fine in my Ubuntu machine with docker:
docker run --rm -t node:18 bash -c "npm i -g google-closure-compiler && google-closure-compiler --version"
Also tried the node:19 image. Both node:18 and node:19 give the same error:
/usr/local/lib/node_modules/google-closure-compiler/node_modules/google-closure-compiler-linux/compiler: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /usr/local/lib/node_modules/google-closure-compiler/node_modules/google-closure-compiler-linux/compiler)
/usr/local/lib/node_modules/google-closure-compiler/node_modules/google-closure-compiler-linux/compiler: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /usr/local/lib/node_modules/google-closure-compiler/node_modules/google-closure-compiler-linux/compiler)
Similar error if I install with yarn global add google-closure-compiler as per the GitHub documentation:
/usr/local/share/.config/yarn/global/node_modules/google-closure-compiler-linux/compiler: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /usr/local/share/.config/yarn/global/node_modules/google-closure-compiler-linux/compiler)
/usr/local/share/.config/yarn/global/node_modules/google-closure-compiler-linux/compiler: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /usr/local/share/.config/yarn/global/node_modules/google-closure-compiler-linux/compiler)
I'm wondering what has changed and what would be the simplest way to fix it. Although there are many questions with glibc errors, haven't found one that had a solution for this particular case.
GLIBC Info
This is what I get in the node:19 based container:
/lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Debian GLIBC 2.31-13+deb11u5) stable release version 2.31.
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 10.2.1 20210110.
libc ABIs: UNIQUE IFUNC ABSOLUTE
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.
So I understand the error, but I don't know why or when the closure compiler started requiring a higher GLIBC version, and most importantly, which docker image should I use to easily solve this.
Nothing Happens With Alpine Image
As an alternative, I tried the node image based on Alpine, which ironically has this warning:
The main caveat to note is that it does use musl libc instead of glibc
and friends, so software will often run into issues depending on the
depth of their libc requirements/assumptions.
Well, actually the libc error is gone now, but google-closure-compiler doesn't seem to do anything, see below:
$ docker run --rm -ti node:19-alpine sh
/ # npm i -g google-closure-compiler
added 27 packages in 30s
/ # google-closure-compiler --version
/ # google-closure-compiler
/ # google-closure-compiler --help
/ #
It literally outputs nothing. Any insights appreciated. As I said, it used to just work.
Ended up reverting to the previous version. This is what was available:
npm view google-closure-compiler versions | grep -v nightly | tail
'20220502.0.0',
'20220601.0.0',
'20220719.0.0',
'20220803.0.0',
'20220905.0.0',
'20221004.0.0',
'20221102.0.0',
'20221102.0.1',
'20230103.0.0',
And installed and tested 20221102.0.1:
docker run --rm -t node:19 bash -c \
"npm i -g google-closure-compiler#20221102.0.1 \
&& google-closure-compiler --version"
Output:
added 27 packages in 7s
Closure Compiler (http://github.com/google/closure-compiler)
Version: v20221102
Solved for now. Better solutions are still welcome.

version `GLIBC_2.29` not found [duplicate]

I'm trying to build a rust app with rust-rocksdb as a dependency.
Using the latest rust docker image to compile and then moving the binary to a debian.
This is how my Dockerfile looks
FROM rust:1.61 as builder
RUN USER=root cargo new --bin fbrust
WORKDIR ./fbrust
COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
RUN apt-get update \
&& apt-get install -y ca-certificates tzdata libclang-dev \
&& rm -rf /var/lib/apt/lists/*
RUN cargo build --release
RUN rm src/*.rs
ADD . ./
RUN rm ./target/release/deps/fbrust*
RUN cargo build --release
FROM debian:buster-slim
ARG APP=/usr/src/app
EXPOSE 5005
ENV TZ=Etc/UTC \
APP_USER=appuser
RUN groupadd $APP_USER \
&& useradd -g $APP_USER $APP_USER \
&& mkdir -p ${APP}
COPY --from=builder /fbrust/target/release/fbrust ${APP}/fbrust
RUN chown -R $APP_USER:$APP_USER ${APP}
USER $APP_USER
WORKDIR ${APP}
CMD ["./fbrust"]
I'm now getting this error(s):
./fbrust: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by ./fbrust)
./fbrust: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.30' not found (required by ./fbrust)
./fbrust: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by ./fbrust)
First of all, I'm confused why do I see both 2.29 and 2.30 required.
I checked within the container and indeed I have 2.28
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii libc-bin 2.28-10 amd64 GNU C Library: Binaries
Is there any other image I can use to achieve compatibility or can I get a hint on what dependencies/setup should I try?
If you look at the list of Debian releases, as of this writing Debian 10 "Buster" is one release behind, and Debian 11 "Bullseye" is the current released stable version. You can also look at the libc6 package listing and see that "Buster" contains libc6 2.28, and "Bullseye" contains libc6 2.31 (both with local patches).
So for your setup, it should work to change the final image to a newer version of Debian, like
FROM debian:bullseye-stable # one newer than buster
Rust builds binaries for the host system by default; This includes the version of glibc of whatever system compiled the binary. The easiest fix is to compile the binary in another docker image using the same version of the same distro.
You should not attempt to fix this by changing distro version to match your binary; You binary will again stop working whenever you upgrage/change the distro on your personal computer (or whatever computer you're using to build the binary).
Alternatively, you can try to compile a static binary: (related question)
rustup target add x86_64-unknown-linux-musl
cargo build --target=x86_64-unknown-linux-musl

How to install older gcc package using APT from a repository?

I have GCC v9. But I'm trying to install a GCC 4.8.1 version to test a library compilation on that very old version of GCC.
The version is not available in the official Ubuntu repos,it is deprecated, but I've found it in other mirrors as told by the official GCC website. This one seems like popular one:
https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
I have very little knowledge of linux package systems except for the basic. I want to keep both versions. So I should do this:
sudo apt -y install gcc-4.8.1 gcc-9
The reason why I want to use this command and not install it from the file, apart from the difficulty of doing that for me, is that I'm following a guide in order to have several GCCs on my system:
https://www.fosslinux.com/39386/how-to-install-multiple-versions-of-gcc-and-g-on-ubuntu-20-04.htm
When I add the url to the sources.list file seems like it is working.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update -q
But when I try to call the install with gcc-4.8.1 or gcc-4.8 , or even gcc-4 the package doesn't exist.
Package gcc-4.8 is not available, but is referred to by another
package. This may mean that the package is missing, has been
obsoleted, or is only available from another source E: Package
'gcc-4.8' has no installation candidate
Also, I don't know if websites like these can be added to the repos list in order to find the package using APT:
http://www.netgull.com/gcc/releases/gcc-4.8.1/
[EDIT]
I downloaded the package from the website I linked. I have no idea how to install this by hand. If only I could find a repository that could help me with this... I have no idea how to make APT help me with the installation.
But I'm trying to install a GCC 4.8.1 version to test a library compilation on that very old version of GCC.
Developers have tools up their sleeve so they don't have to install dependencies and bloating their systems for every library (and every configuration of that library!) they want to try out and test.
Use docker. You could write for example a testing script, assuming your project uses make:
# test_my_lib_in_gcc-4.8.sh
#!/bin/sh
docker run -ti --rm -v $PWD:/project -w /project gcc:4.8 -u $UID:$GID sh <<EOF
make && make test
EOF
that will compile and test your application in using 4.8 gcc. Consider how easy it is to change gcc version - just change the number. You could test your library in gcc, in different versions, and using other compilers and on different distributions to make sure it works for others. If you're a developer of the library, write an automatized CI pipeline that would automatically test your application each commit in specific docker environment, using ex. https://docs.gitlab.com/ee/ci/README.html or https://travis-ci.org/ .

some error failed to run custom build command for `librocksdb-sys v6.11.4`

I tried to create my first substrate chain. Create Your First Substrate Chain
But I got some error while compiling substrate.
failed to run custom build command for librocksdb-sys v6.11.4
Does anybody know how to fix this problem?
You need to install additional library:
sudo apt install clang should help.
sudo apt-get update
sudo apt install make clang pkg-config libssl-dev
This should do the trick.
Reference: https://github.com/paritytech/polkadot/issues/65
From #apopiak
Are you on Apple M1? If, so there are currently issues with building rocksdb there. See here an approach: vikiival.medium.com/run-substrate-on-apple-m1-a2699743fae8
Also others have reported needing to:
You need clone the rust-rocksdb repo and checkout the commit listed here: https://github.com/substrate-developer-hub/substrate-node-template/issues/122 then you can create a config.toml file in your .cargo folder in your home directory and add a path to that cloned repo
You had better update cargo to the nightly version and then try it.
If it keep in stuck error try comment commands, you may will need to study link.
#rustup component add --toolchain=nightly rust-src rustfmt
rustup target add wasm32-unknown-unknown
#apt-get install llvm clang linux-headers-"$(uname -r)" #
apt install llvm clang
cargo build --release
#cargo fix --allow-dirty #cargo fix --edition
#lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
#ldconfig --version
ldconfig (Ubuntu GLIBC 2.31-0ubuntu9.2) 2.31
#cargo --version
cargo 1.60.0-nightly (25fcb13 2022-02-01)
#rustc --version
rustc 1.60.0-nightly (f624427f8 2022-02-06)
#rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /root/.rustup
installed targets for active toolchain
--------------------------------------
wasm32-unknown-unknown
x86_64-unknown-linux-gnu
active toolchain
----------------
nightly-x86_64-unknown-linux-gnu (default)
rustc 1.60.0-nightly (f624427f8 2022-02-06)
#ArmanRiazi.blockchain#Substrate#Dr.GavinWood
For details:
Walk-Through/Substrate/NodeSetup
You need to update the to this version: "6.20.3"
checksum = "c309a9d2470844aceb9a4a098cf5286154d20596868b75a6b36357d2bb9ca25d"
am running on M1!

Bitbucket pipeline installing the wrong version of cmake

When I apt-get install cmake in my Bitbucket pipeline, it installs version 3.0.2. This then leads to an error "CMake 3.7.2 or higher is required. You are running version 3.0.2". How can I install cmake version 3.7.2 or higher in my .yml?
bitbucket-pipelines.yml
image: gcc:6.5
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- apt-get update && apt-get -y install cmake
- cmake -B build .
Error:
+ cmake -B build .
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.7.2 or higher is required. You are running version 3.0.2
This isn't really a pipelines issue. I'll walk through the troubleshooting process to identify the problem and a possible solution. You could pursue other solutions to install your desired version but hopefully following the approach here will help you in future.
Full disclosure, I work for Atlassian - though not on the Bitbucket Pipelines team :)
The version of cmake that you see being installed is actually related to the third party base image you're using, gcc:6.5. You can test/verify this on your own machine:
$ docker run --rm -it gcc:6.5 bash
root#77d4fde67119:/# apt-get update && apt-get -y install cmake
root#77d4fde67119:/# cmake --version
cmake version 3.0.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
We can see the gcc:6.5 image is based on Debian Jessie:
root#77d4fde67119:/# cat /etc/os-release | grep PRETTY
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
If you look up the default cmake package for Jessie you'll find that it's v3.0.2: https://packages.debian.org/jessie/devel/cmake
A little more digging will show you that newer Debian versions package newer versions of cmake by default: Stretch or Buster will package 3.7 or 3.13 respectively. So the solution to your issue is using a newer version of the gcc base image based on a more recent Debian version:
Let's try it again with the gcc:7 base image:
$ docker run --rm -it gcc:7 bash
root#26e82f7b5e56:/# cat /etc/os-release | grep PRETTY
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
Well, that's a good sign: gcc:7 is based on Debian Buster. Buster ships 3.13: https://packages.debian.org/buster/devel/cmake
root#26e82f7b5e56:/# apt-get update && apt-get -y install cmake
root#26e82f7b5e56:/# cmake --version
cmake version 3.13.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
There you have it: a version above 3.7.
If you can't use this version of gcc, of course, you'll need to look at a different solution. But hopefully this helps to illustrate the source of your issue and how you can investigate these kinds of issues in future.

Resources