Compiling and Installing glibc x.y on Debian
Compiling and Installing glibc x.y on Debian
Compiling and Installing glibc x.y on Debian
Prerequisites
1
sudo apt-get install automake autoconf libtool make gcc
If you’re unsure of your system’s host type, you can run the following command to check:
1
gcc -dumpmachine
For demo, we will use libc 2.1
Visit the GNU C Library (glibc) website
Find libc in https://ftp.gnu.org/gnu/glibc/
- Download the Source Code:
1 2 3
wget https://ftp.gnu.org/gnu/glibc/glibc-2.1.3.tar.gz tar -xvzf glibc-2.1.3.tar.gz cd glibc-2.1.3
- Prepare the Build Environment: Create a separate build directory to keep your source directory clean:
1 2
mkdir build cd build
- Configure the Build You need to specify the installation directory where the compiled glibc will be installed. For example, let’s install it in
/opt/glibc-2.1.3
:1
../configure --prefix=/opt/glibc-2.1.3 --enable-add-ons
Adjust the
--prefix
option to your preferred installation directory. You can also specify other options like--enable-debug
if you want to build a debug version. - Compile the Library Compile the library using
make
:1
make -j$(nproc)
- Install the Library After successful compilation, install the library:
1
sudo make install
- Update Library Cache Update the dynamic linker run-time bindings:
1
sudo ldconfig
- Linking Against Your Custom glibc To link your program with the specific glibc version, you need to specify the path to the glibc installation using the
-Wl
,-rpath
and-L
options:1
gcc -Wl,-rpath=/opt/glibc-2.31/lib -L/opt/glibc-2.31/lib -I/opt/glibc-2.31/include hello.c -o hello
This post is licensed under CC BY 4.0 by the author.