First of all, don't put an alternate libc (or alternate version of your libc) in a path searched by the normal include and library search (both link-time and runtime library search) for your main system one. This is a recipe for disaster. Installing a different glibc in /usr/local/ does avoid clobbering your system one, but now you just have two installed in places where the same tools can see and use them.

To do this right, you really need a full separate toolchain (gcc, binutils) in some completely separate path (like ~/my_glibc_root/... or /opt/alt_glibc_root/...). I'm not sure if there's a recommended way to do this. The glibc build procedures in Linux From Scratch might be a good place to look for ideas. In theory it can be done in a single stage; I do that with musl libc in musl-cross-make by careful use of intermediate make rules in the gcc build system. But applying the same idea to glibc probably requires some extra care.

Answer from R.. GitHub STOP HELPING ICE on Stack Overflow
Top answer
1 of 2
3

First of all, don't put an alternate libc (or alternate version of your libc) in a path searched by the normal include and library search (both link-time and runtime library search) for your main system one. This is a recipe for disaster. Installing a different glibc in /usr/local/ does avoid clobbering your system one, but now you just have two installed in places where the same tools can see and use them.

To do this right, you really need a full separate toolchain (gcc, binutils) in some completely separate path (like ~/my_glibc_root/... or /opt/alt_glibc_root/...). I'm not sure if there's a recommended way to do this. The glibc build procedures in Linux From Scratch might be a good place to look for ideas. In theory it can be done in a single stage; I do that with musl libc in musl-cross-make by careful use of intermediate make rules in the gcc build system. But applying the same idea to glibc probably requires some extra care.

2 of 2
0

Second Try Command: In second try, I am using "-I" & "-L" GCC command options.

gcc -Wall -g -I/usr/local/glibc/include -o main main.c -L/usr/local/glibc/lib -Wl,--rpath=/usr/local/glibc/lib -Wl,--dynamic-linker=/usr/local/glibc/lib/ld-linux-x86-64.so.2

This command is almost correct. The thrd_create and thrd_join functions are defined in libpthread, which you didn't link against.

Add -pthread to your compile command, and the link should succeed.

P.S. R's advice of not installing alternate GLIBC into /usr/local is also a good one.

🌐
GitHub
github.com › sdwru › glibc-centos-8 › blob › master › BUILD › glibc-2.28 › INSTALL
glibc-centos-8/BUILD/glibc-2.28/INSTALL at master · sdwru/glibc-centos-8
glibc for Centos v8 including 2.6.32 kernel compatibility as required when using OpenVZ v6. The master and release branches track official source and the custom branches contain the changes. https://github.com/sdwru/glibc-centos-8/releases contains an OVZ6 template and the compiled RPM packages - glibc-centos-8/BUILD/glibc-2.28/INSTALL at master · sdwru/glibc-centos-8
Author   sdwru
Discussions

How to install GLIBC version 2.29 in the Linux Binary Compat layer? | The FreeBSD Forums
Activitywatch is a program that is used to track the amount of time that is spent on a computer, they only officially have support for Windows, Linux and MacOS. I have installed the Linux Binary compatibility layer and installed activitywatch under /compat/ubuntu/opt/activitywatch, when I run... More on forums.freebsd.org
🌐 forums.freebsd.org
September 5, 2023
centos7 - Install package failed because of dependency problem - Stack Overflow
to update a package with yum or rpm the install failed because of a dependency issue rpm -ivh sudo-1.8.29-6.el8_3.1.x86_64.rpm warning: sudo-1.8.29-6.el8_3.1.x86_64.rpm: Header V3 RSA/SHA256 Signa... More on stackoverflow.com
🌐 stackoverflow.com
I compiled Glibc 2.29, the installation was unsuccessful and I want to remove it. How to proceed?
I compiled a version of Glibc (2.29) required by a game that I downloaded from the internet. I did all the procedures listed on a site (upgrade - How to update glibc to 2.14 in CentOS 6.5 - Unix & Linux Stack Exchange) but the installation gave an error in the middle of the process and my computer ... More on forum.zorin.com
🌐 forum.zorin.com
1
0
March 22, 2021
arch linux - GLIBC_2.29 can not be found for avrdude even after downloading it - Unix & Linux Stack Exchange
I have a bit of a struggle with using avrdude to flash my microcontroller. It dependends of libm.so.6 GLIBC_2.29 which it cannot find. It looks under /usr/lib/libm.so.6 where this file does actua... More on unix.stackexchange.com
🌐 unix.stackexchange.com
May 31, 2019
🌐
Pkgs.org
pkgs.org › download › glibc(x86-64)
Glibc(x86-64) Download for Linux (rpm)
Download glibc(x86-64) linux packages for AlmaLinux, Amazon Linux, CentOS, Fedora, Mageia, OpenMandriva, openSUSE, PCLinuxOS, Rocky Linux · Filter: Distros: all Arches: arm intel Types: official thirdparty · AlmaLinux 9 · AlmaLinux 8 · Amazon Linux 2 · Amazon Linux 1 ·
🌐
FreeBSD
forums.freebsd.org › server and networking › emulation and virtualization
How to install GLIBC version 2.29 in the Linux Binary Compat layer? | The FreeBSD Forums
September 5, 2023 - /usr/bin/ld: /root/glibc-2.29/build/elf/librtld.os: in function `_rtld_main_check': /root/glibc-2.29/elf/../sysdeps/x86/dl-prop.h:33: undefined reference to `_dl_cet_check' /usr/bin/ld: /root/glibc-2.29/elf/../sysdeps/x86/dl-prop.h:33: undefined reference to `_dl_cet_check' /usr/bin/ld: /root/glibc-2.29/elf/../sysdeps/x86/dl-prop.h:33: undefined reference to `_dl_cet_check' /usr/bin/ld: /root/glibc-2.29/build/elf/librtld.os: in function `_dl_open_check': /root/glibc-2.29/elf/../sysdeps/x86/dl-prop.h:41: undefined reference to `_dl_cet_open_check' /usr/bin/ld: /root/glibc-2.29/build/elf/ld.so.n
Top answer
1 of 3
23

Check it is actually needed

Firstly check the python application as it could be out of date and is probably misreading the glibc version. CentOS shows the base version as installed and is patched to keep up with changes and it could just be a case of fixing the version that is being looked for in the code as a quick fix, but if the application is being actively developed you need to let the developers know or fork it for yourself if you can.

An up to date glibc on CentOS 7 should be 2.17-196.el7_4.2

If it is needed, Containerise

If it's absolutely necessary to run this application, the official RHEL approach would be to containerize, but you would still need to provide a working glibc, which wouldn't be possible with stock CentOS 7.

As a last resort, install glibc in a nonstandard location

If this isn't viable, and as an absolute last resort, it is possible to install a newer version of glibc than 2.18 as that is 9 years old now and glibc has been updated for several vulnerabilities and I'm not sure off the top of my head if it will build with the version of make in CentOS 7, but any newer version should work as follows:

  • This can potentially affect the functionality of your computer so make sure you know what you are doing

You can build the version of glibc you require elsewhere on your server and add it to LD_LIBRARY_PATH for the application. Note this must only be done for the application only.

wget http://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz
tar zxvf glibc-2.18.tar.gz
cd glibc-2.18
mkdir build
cd build
../configure --prefix=/opt/glibc-2.18
make -j4
sudo make install

Then to run a binary you need to use patchelf to update its interpreter

patchelf --set-interpreter /opt/glibc-2.18/lib/ld-linux-x86-64.so.2 program_you_are_running

And you need to enable it to find the new glibc library, either by

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/glibc-2.18/lib

Or you can use patchelf to update the binary's rpath (you can combine this with the previous pathelf command)

patchelf --set-rpath /opt/glibc-2.18/lib:/usr/lib64 program_you_are_running

If you change LD_LIBRARY_PATH don't export it for the whole system because all the binaries unmodified by patchelf will segfault.

/opt is the standard place to install third-party applications and libraries but you can use any path away from the system paths.

2 of 3
4

In the end,I did not have to upgrade GLIBC. The gdc-client tool I downloaded through R seemed to be for Ubuntu and not CentOS, though I did it on CentOS 7. I then downloaded the gdc-client for CentOS and it worked fine.

🌐
Ngelinux
ngelinux.com › home › how to install glibc package version 2.28+ on rhel 7 unofficially for testing purposes?
How to install glibc package version 2.28+ on RHEL 7 unofficially for testing purposes? | New Generation Enterprise Linux
June 22, 2022 - CentOS or RHEL does not officially support this and provides glibc version 2.17 as official version. Since these packages affect the core OS, upgrading unofficial version makes your OS out of support.
Find elsewhere
🌐
The Linux Cluster
thelinuxcluster.com › 2023 › 06 › 30 › compiling-glibc-2-29-at-centos-7
Compiling glibc-2.29 at CentOS-7 – The Linux Cluster
July 9, 2023 - Step 1: Download the glibc To Download the glibc-2.29, do download at https://ftp.gnu.org/gnu/glibc/ Step 2: Compile and Build the glibc libraries # tar zxvf glibc-2.29.tar.gz # cd glibc-2.29 # mkdir build # cd build Step 3: Compile and install ...
🌐
GitHub
github.com › arkmanager › ark-server-tools › wiki › Install-of-required-versions-of-glibc-and-gcc-on-RHEL-CentOS
Install of required versions of glibc and gcc on RHEL CentOS
June 23, 2015 - RHEL/CentOS 6.6 and below have an outdated version of glibc and gcc, you can make ARK server works manually upgrading these libraries: yum groupinstall "Development tools" yum install glibc-devel.i686 glibc-i686 · cd /tmp wget http://ftp.g...
Author   arkmanager
🌐
Remi's RPM Repository
rpms.remirepo.net › rpmphp › zoom.php
Packages in Fedora / RHEL / CentOS / EPEL - Package: glibc
Show more informations from pkgdb · The Fedora Project is maintained and driven by the community and sponsored by Red Hat. This is a community maintained site. Red Hat is not responsible for content
🌐
Red Hat
access.redhat.com › discussions › 3244811
Red Hat Customer Portal - Access to 24x7 support and knowledge
If you are developing programs which : will use the standard C libraries, your system needs to have these : standard object files available in order to create the : executables. : : Install glibc-devel if you are going to develop programs which will : use the standard C libraries.
🌐
Liquid Web
liquidweb.com › home › how to update the glibc (gnu libc) in centos / red hat
How to Update the glibc (GNU libc) in CentOS / Red Hat | Liquid Web
December 3, 2024 - Looking to update glibc (GNU libc) in CentOS or Red Hat? Learn how to upgrade this critical library and ensure your system’s stability and security.
🌐
CentOS Repositories
centos.pkgs.org › 8 › centos-baseos-x86_64 › glibc-2.28-127.el8.x86_64.rpm.html
Glibc Download (EOPKG, RPM, TXZ, XBPS, XZ, ZST)
Download glibc packages for AlmaLinux, ALT Linux, Amazon Linux, Arch Linux, CentOS, Fedora, KaOS, Mageia, OpenMandriva, openSUSE, PCLinuxOS, Rocky Linux, Slackware, Solus, Void Linux
🌐
Pkgs.org
pkgs.org › download › libc.so.6(GLIBC_2.29)(64bit)
Libc.so.6(GLIBC_2.29)(64bit) Download for Linux (rpm)
Download libc.so.6(GLIBC_2.29)(64bit) linux packages for ALT Linux, CentOS, Fedora, Mageia, OpenMandriva, openSUSE, PCLinuxOS · Filter: Distros: all Arches: arm intel Types: official thirdparty · ALT Linux Sisyphus · CentOS 7 · Fedora Rawhide · Fedora 34 · Fedora 33 · Fedora 32 · Mageia Cauldron · Mageia 8 ·
Top answer
1 of 1
1

Please note that the installed glibc is an incomplete C runtime. In order to complete the C runtime you may need to copy in additional headers that match the compiler you are using since the use of --sysroot will restrict their lookup to the sysroot.

It is very possible to have multiple versions of glibc on the same system (we do that every day).

However, you need to know that glibc consists of many pieces (200+ shared libraries) which all must match. One of the pieces is ld-linux.so.2, and it must match libc.so.6, or you'll see the errors you are seeing.

The absolute path to ld-linux.so.2 is hard-coded into the executable at link time, and can not be easily changed after the link is done.

To build an executable that will work with the new glibc, do this:

g++ main.o -o myapp ... \
   -Wl,--rpath=/path/to/newglibc \
   -Wl,--dynamic-linker=/path/to/newglibc/ld-linux.so.2

The -rpath linker option will make the runtime loader search for libraries in /path/to/newglibc (so you wouldn't have to set LD_LIBRARY_PATH before running it), and the -dynamic-linker option will "bake" path to correct ld-linux.so.2 into the application.

If you can't relink the myapp application (e.g. because it is a third-party binary), not all is lost, but it gets trickier. One solution is to set a proper chroot environment for it. Another possibility is to use rtldi and a binary editor.

SOLUTION #1

LD_PRELOAD='mylibc.so anotherlib.so' program

Solution #2

compile your own glibc without dedicated GCC and use it

This setup might work and is quick as it does not recompile the whole GCC toolchain, just glibc.

But it is not reliable as it uses host C runtime objects such as crt1.o, crti.o, and crtn.o provided by glibc. This is mentioned at: https://sourceware.org/glibc/wiki/Testing/Builds?action=recall&rev=21#Compile_against_glibc_in_an_installed_location Those objects do early setup that glibc relies on, so I wouldn't be surprised if things crashed in wonderful and awesomely subtle ways.

For a more reliable setup, see Setup 2 below.

Build glibc and install locally:

export glibc_install="$(pwd)/glibc/build/install"

git clone git://sourceware.org/git/glibc.git
cd glibc
git checkout glibc-2.28
mkdir build
cd build
../configure --prefix "$glibc_install"
make -j `nproc`
make install -j `nproc`

Setup 1: verify the build

test_glibc.c

#define _GNU_SOURCE
#include <assert.h>
#include <gnu/libc-version.h>
#include <stdatomic.h>
#include <stdio.h>
#include <threads.h>

atomic_int acnt;
int cnt;

int f(void* thr_data) {
    for(int n = 0; n < 1000; ++n) {
        ++cnt;
        ++acnt;
    }
    return 0;
}

int main(int argc, char **argv) {
    /* Basic library version check. */
    printf("gnu_get_libc_version() = %s\n", gnu_get_libc_version());

    /* Exercise thrd_create from -pthread,
     * which is not present in glibc 2.27 in Ubuntu 18.04.
     * https://stackoverflow.com/questions/56810/how-do-i-start-threads-in-plain-c/52453291#52453291 */
    thrd_t thr[10];
    for(int n = 0; n < 10; ++n)
        thrd_create(&thr[n], f, NULL);
    for(int n = 0; n < 10; ++n)
        thrd_join(thr[n], NULL);
    printf("The atomic counter is %u\n", acnt);
    printf("The non-atomic counter is %u\n", cnt);
}

Compile and run with test_glibc.sh:

#!/usr/bin/env bash
set -eux
gcc \
  -L "${glibc_install}/lib" \
  -I "${glibc_install}/include" \
  -Wl,--rpath="${glibc_install}/lib" \
  -Wl,--dynamic-linker="${glibc_install}/lib/ld-linux-x86-64.so.2" \
  -std=c11 \
  -o test_glibc.out \
  -v \
  test_glibc.c \
  -pthread \
;
ldd ./test_glibc.out
./test_glibc.out

The program outputs the expected:

gnu_get_libc_version() = 2.28
The atomic counter is 10000
The non-atomic counter is 8674

Command adapted from https://sourceware.org/glibc/wiki/Testing/Builds?action=recall&rev=21#Compile_against_glibc_in_an_installed_location but --sysroot made it fail with:

cannot find /home/ciro/glibc/build/install/lib/libc.so.6 inside /home/ciro/glibc/build/install

so I removed it.

ldd output confirms that the ldd and libraries that we've just built are actually being used as expected:

+ ldd test_glibc.out
        linux-vdso.so.1 (0x00007ffe4bfd3000)
        libpthread.so.0 => /home/ciro/glibc/build/install/lib/libpthread.so.0 (0x00007fc12ed92000)
        libc.so.6 => /home/ciro/glibc/build/install/lib/libc.so.6 (0x00007fc12e9dc000)
        /home/ciro/glibc/build/install/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007fc12f1b3000)

The gcc compilation debug output shows that my host runtime objects were used, which is bad as mentioned previously, but I don't know how to work around it, e.g. it contains:

COLLECT_GCC_OPTIONS=/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crt1.o

Setup 1: modify glibc

Now let's modify glibc with:

diff --git a/nptl/thrd_create.c b/nptl/thrd_create.c
index 113ba0d93e..b00f088abb 100644
--- a/nptl/thrd_create.c
+++ b/nptl/thrd_create.c
@@ -16,11 +16,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */

+#include <stdio.h>
+
 #include "thrd_priv.h"

 int
 thrd_create (thrd_t *thr, thrd_start_t func, void *arg)
 {
+  puts("hacked");
   _Static_assert (sizeof (thr) == sizeof (pthread_t),
                   "sizeof (thr) != sizeof (pthread_t)");

Then recompile and re-install glibc, and recompile and re-run our program:

cd glibc/build
make -j `nproc`
make -j `nproc` install
./test_glibc.sh

and we see hacked printed a few times as expected.

This further confirms that we actually used the glibc that we compiled and not the host one.

Tested on Ubuntu 18.04.

Sources:

https://stackoverflow.com/questions/847179/multiple-glibc-libraries-on-a-single-host/851229#851229

https://sourceware.org/glibc/wiki/Testing/Builds?action=recallrev=21#Compile_against_glibc_in_an_installed_location

🌐
Bits and Dragons
bitsanddragons.wordpress.com › 2020 › 08 › 26 › glibc_2-25-compile-on-centos-7-8
GLIBC_2.25 compile on CentOS 7.8 | Bits and Dragons
September 9, 2020 - I previously had issues with GLIBC, now on my current CentOS 7.8 I can’t update it via yum anymore. This is my (simple) recipe: wget https://ftp.gnu.org/gnu/glibc/glibc-2.25.tar.gz tar -xvzf glibc-2.25.tar.gz cd glibc-2.25/ mkdir build cd build/ ../configure --prefix=/opt/local/glibc-2.25/ make -j8 make install