Next Previous Contents

5. Installing as the primary C library.

This section covers installing glibc 2 as your primary C library. Any new programs you compile will be linked with this library, unless you use special compile options to link with another version.

If you are are using Redhat or Debian and have downloaded the appropriate rpm or deb files, see the Redhat or Debian installion instructions. You can then skip this section.

5.1 Building the library from source.

This section explains how to compile glibc 2 and add-ons from the sources. You must compile the library if you want to change optimization or configuration options or use a package you do not have the binaries for.

Prerequisites.

On an i586@133 with 64 MB of RAM, it takes about 3 hours to compile with full libraries with add-ons. On a loaded i686@200, it takes about half an hour.

Extracting the source.

You need to extract the source from the archives so you can compile it. The best way to do this is:

 tar xzf glibc-2.0.6.tar.gz
 cd glibc-2.0.6
 tar xzf ../glibc-linuxthreads-2.0.6.tar.gz
 tar xzf ../glibc-crypt-2.0.6.tar.gz
 tar xzf ../glibc-localedata-2.0.6.tar.gz
 
This will put linuxthreads, crypt, and localedata directories in the glibc-2.0.6 directory where configure can find these add-ons.

Configuring.

In the glibc-2.0.6 directory, create a directory named compile, and cd into it. All work will be done in this directory, which will simplify cleaning up. (The developers have not been very concerned with getting 'make clean' perfect yet.)

mkdir compile
cd compile
Run ../configure. To use the add-on packages, you need to specify them with --enable-add-ons, such as --enable-add-ons=linuxthreads,crypt,localedata. You probably will also want to specify paths where it will be installed. To match the standard linux distributions, specify --prefix=/usr. (When a prefix of /usr is specified on a linux system, configure knows to adjust other paths to place libc.so and other important libraries in /lib.) The whole configure line would be:
 ../configure --enable-add-ons=linuxthreads,crypt,localedata --prefix=/usr

Compiling.

To compile and verify, run:

 make
 make check
 

5.2 Preparing for installation.

Now you need to move some files around to prepare for the new library, whether you are installing from source or binaries. Any new program compiled will be linked to glibc, but old programs which are not statically linked will still depend on libc 5, so you can not just overwrite the old version.

  1. Create a new directory to hold the old files to:
     mkdir -p /usr/i486-linuxlibc5/lib
     
    
  2. The old header files must be evacuated from /usr/include:
     mv /usr/include /usr/i486-linuxlibc5/include
     
    
  3. Create a new include directory and set up the links to other include directories:
     mkdir /usr/include
    
     ln -s /usr/src/linux/include/linux /usr/include/linux
     ln -s /usr/src/linux/include/asm /usr/include/asm
     ln -s /usr/X11R6/include/X11 /usr/include/X11
     ln -s /usr/lib/g++-include /usr/include/g++
     
    
    The links may need adjusting according to your distribution. At least Slackware puts g++ headers in /usr/local/g++-include, while Debian puts the headers in /usr/include/g++, and links /usr/lib/g++-include to /usr/include/g++. In the later case, you probably will want to move the original g++ include directory back to /usr/include.
  4. Restore any extra header files and links. Some non-standard libraries such as ncurses put files in /usr/include or put a link to their include directories in the /usr/include. These files and links need to be restored in order to use the extra libraries properly.
  5. Add your new library directory (such as /usr/i486-linuxlibc5/lib) at the top of your /etc/ld.so.conf file. You should have ld.so 1.8.8 or better installed to avoid getting strange messages once glibc is installed.
  6. Move/copy all the old C libraries into the new directory.
     mv /usr/lib/libbsd.a /usr/i486-linuxlibc5/lib
     mv /usr/lib/libc.a /usr/i486-linuxlibc5/lib
     mv /usr/lib/libgmon.a /usr/i486-linuxlibc5/lib
     mv /usr/lib/libm.a /usr/i486-linuxlibc5/lib
     mv /usr/lib/libmcheck.a /usr/i486-linuxlibc5/lib
     mv /usr/lib/libc.so /usr/i486-linuxlibc5/lib
     mv /usr/lib/libm.so /usr/i486-linuxlibc5/lib
     cp /lib/libm.so.5.* /usr/i486-linuxlibc5/lib
     cp /lib/libc.so.5.* /usr/i486-linuxlibc5/lib
     
    
    libm.so.5 and libc.so.5 should be copied and not moved if /usr is a seperate partition from /, because they are required by programs used to start linux and must be located on the root drive partition.
  7. Move the /usr/lib/*.o files into the new directory.
     mv /usr/lib/crt1.o /usr/i486-linuxlibc5/lib
     mv /usr/lib/crti.o /usr/i486-linuxlibc5/lib
     mv /usr/lib/crtn.o /usr/i486-linuxlibc5/lib
     mv /usr/lib/gcrt1.o /usr/i486-linuxlibc5/lib
     
    
  8. Update your library cache after your libraries are moved.
     ldconfig -v
     
    

5.3 Installing from the binary package.

If you are installing glibc from precompiled binaries, you must:

 cd /
 gzip -dc glibc-2.0.bin.i386.tar.gz | tar tvvf -
 gzip -dc glibc-crypt-2.0.bin.i386.tar.gz | tar tvvf -
 ldconfig -v
 
If you have a different architecture or version, substitute the proper file names.

5.4 Installing from the source.

To install the library from source, run:

 make install
 ldconfig -v
 

5.5 Updating the gcc specs.

The final step of the installation (for both binary and source installs) is to update the gcc specs file so you can link your programs properly. To determine which specs file is the one used by gcc, use:

 % gcc -v
 reading specs from /usr/lib/gcc-lib/i486-unknown-linux/2.7.2.2/specs
 gcc version 2.7.2.2
 

In this case, i486-unknown-linux is the system, and 2.7.2.2 is the version. You need to copy the /usr/lib/gcc-lib/<system> to the old system directory:

 cd /usr/lib/gcc-lib/
 cp -r i486-unknown-linux i486-linuxlibc5
 

Change into the original directory and version directory

 cd /usr/lib/gcc-lib/i486-unknown-linux/2.7.2.2
 

and edit the file specs found in this directory. In this file, change /lib/ld-linux.so.1 to /lib/ld-linux.so.2. You also need to remove all expressions %{...:-lgmon} in the file, since glibc does not use the gmon library for profiling. A sample specs file can be found in the Sample specs file section.

5.6 Testing your installation.

To test the installation, create the following program in a file glibc.c:

 #include <stdio.h>

 main()
 {
     printf("hello world!\n");
 }
 
and compile the program.
 % gcc glibc.c -o glibc
 
Use ldd to verify the program was linked with glibc2, and not your old libc:
 % ldd glibc
 libc.so.6 => /lib/libc.so.6 (0x4000e000)
 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
 
If this compiles and generates "hello world!" when run, the installation was successful.


Next Previous Contents