A Solution to Version GLIBC_2.XX Not Found

Jan 15, 2025 by Zacharia Mansouri | 376 views

Linux

https://cylab.be/blog/388/a-solution-to-version-glibc-2xx-not-found

If you’ve ever tried running a program on Linux and encountered this error message then you’re familiar with the frustrating issue of missing or mismatched glibc versions. This specific error occurs when a program requires a version of the GNU C Library (glibc) that isn’t installed on your system, or is incompatible with the one you have. In this post, we’ll dive into the steps to resolve the issue, including how to install a specific version of glibc locally, so your program runs smoothly without upgrading your system-wide libraries.

linux-penguin-handling-glibc-token.jpg

What is the GNU C Library

The GNU C Library, often referred to as glibc, is a core component of the Linux operating system. It provides the standard C libraries used for system calls, input/output operations, memory management, and other low-level functionalities. This makes it a critical part of almost every application on Linux.

Checking glibc Version

To check which version of glibc is installed on your system, you can use the ldd utility. This command lists the shared libraries required by a program, which includes glibc. Here’s how to check your glibc version:

ldd --version

This will output something like:

ldd (Ubuntu GLIBC 2.XX-XubuntuX.XX) 2.XX
...

Here, 2.XX indicates the version of glibc currently installed on your system.

Common Issue: Missing GLIBC Version

You may encounter an error when running a binary that requires a specific version of glibc that is not installed on your system. The error might look like this:

./my-binary: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.XX' not found (required by ./my-binary)

In this case, the binary my-binary needs glibc version 2.XX, but your system either has another version or none at all.

Identifying Statically or Dynamically Linked Libraries

You can check whether the program is linked dynamically or statically using the ldd command. If the program is dynamically linked, ldd will list the shared libraries it depends on, including glibc.

ldd ./my-binary

This might output something like:

./my-binary: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.XX' not found (required by ./my-binary)
	linux-vdso.so.1 (0x0000XXXXXXXXXXXX)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000XXXXXXXXXXXX)
	/lib64/ld-linux-x86-64.so.2 (0x0000XXXXXXXXXXXX)
		

If the binary is statically linked, ldd will return 1 instead of listing shared libraries. To confirm, you can check the return code of the ldd command:

echo $?
  • 0 means the binary is dynamically linked.
  • 1 means it’s statically linked.

Note that, in this situation, the error we encountered (missing glibc version) is enough to guess the library is dynamically loaded.

Installing the Required glibc Version

If you need a specific version of glibc for your program, you may choose to install it locally, especially if you don’t want to update the version globally on your system. Here’s how to install it:

  1. Download and extract the source code for the required version:
wget http://ftp.gnu.org/gnu/libc/glibc-2.XX.tar.gz
tar -xvzf glibc-2.XX.tar.gz
  1. Create a build directory and install dependencies:
cd glibc-2.XX
mkdir build
cd build
sudo apt-get install -y gcc make gdb
sudo apt-get install -y texinfo gawk bison sed
sudo apt-get install -y python3-dev python3-pip python-is-python3
sudo pip install pexpect
  1. Configure the build and compile:
# Configure
../configure --prefix=/opt/glibc-2.XX \
  --host=x86_64-linux-gnu \
  --build=x86_64-linux-gnu \
  CC="gcc -m64" \
  CXX="g++ -m64" \
  CFLAGS="-O2" \
  CXXFLAGS="-O2"

make -j$(nproc)

# Optionally:
# make check 
  1. Install it (you may need sudo rights, note below):
make install

You might need to execute make install with sudo rights, if you don’t have them for the target directory, which is probably the case with /opt/glibc-2.XX as a target directory here.

Locale Issues During Installation

When installing glibc, you might encounter errors such as:

libc.texinfo:21: @include: could not find dir-add.texi

This issue is related to locale settings on your computer, which are affecting the build process for glibc and causing missing .texi files. This happens because some parts of the build system may not find certain files or resources due to language/locale-specific directories or configurations.

To resolve this, you can temporarily change the locale to English while building glibc. This will help ensure that the required .texi files are found and other locale-related issues are avoided. Before running the make -j$(nproc) or make install commands, set the environment variables to use the C or en_US.UTF-8 locale:

export LANG=C
export LC_ALL=C

or

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

It is recommended to run make clean after an unsuccessful installation, before running a new one.

Note that the C locale is the default C (or POSIX) locale, which is a minimal, standard locale used for basic system operations. It avoids locale-specific formatting and language settings, ensuring consistent behavior across systems regardless of language.

Running Your Binary with a Custom glibc Version

Once you have the required glibc version installed locally, you can run your binary using the custom library by setting either the LD_PRELOAD or LD_LIBRARY_PATH environment variables.

Option 1: Using LD_PRELOAD

The LD_PRELOAD environment variable forces the dynamic linker to load a specific library before any other libraries. You can specify the full path to the required libc.so.6.

LD_PRELOAD=/path/to/your/libc.so.6 ./my-binary

Replace /path/to/your/libc.so.6 with the actual path to the required libc.so.6 (/opt/glibc-2.XX/lib/libc.so.6 in our example).

Option 2: Using LD_LIBRARY_PATH

The LD_LIBRARY_PATH environment variable specifies directories where the dynamic linker should search for shared libraries. You can point it to the directory containing the required libc.so.6.

LD_LIBRARY_PATH=/path/to/your/library/dir:$LD_LIBRARY_PATH ./my-binary

This will direct the dynamic linker to look in the specified directory for shared libraries before searching the default paths.

Conclusion

The GNU C Library (glibc) is a vital component of the Linux system, providing core functionality to applications. When dealing with missing or mismatched glibc versions, you can either update the system version or install the required version locally. The use of environment variables like LD_PRELOAD or LD_LIBRARY_PATH allows you to run your program with the correct version of glibc without affecting other programs on your system.

References

This blog post is licensed under CC BY-SA 4.0

This website uses cookies. More information about the use of cookies is available in the cookies policy.
Accept