Glibc2 on Linux: libstdc++

Note that this documentation is historic. It may no longer be very relevant. There will be no updates or further releases.

Introduction

This is the final step in installing glibc-2. To compile C++ programs, one needs the C++-library. Because this library uses the C-library, you need separate versions for the old libc-5 target and the new libc-6 target. You will see that the commands for compiling both versions are exactly the same, except for an optional parameter indicating the current machine type and a different installation directory. Therefor, compilation of this library is a good illustration of how to use the new compilation environment. In this specific case, a small patch and a setting of the target_alias are needed; for almost any other program, you will not have to bother about it.

Note that starting with version 2.8, libstdc++ is the standard C++ library; libg++ is now reduced to an optional add-on for backward compatibility. I will show here how to compile libstdc++, including the libg++ add-on. You can optionally ignore and not install the latter, though.

Preparing for compilation

Even though this is a relative step-by-step guide, it would be wise to read the most important documentation yourself; especially the README and INSTALL files. The newest version as of the writing of this document is libstdc++-2.8.1.1 with libg++-2.8.1.1a; installation of newer versions may differ, and some of the patches may not apply cleanly.

Unpacking the sources

Unpack the sources by executing the following sequence of commands, substituting the directory that contains your sources for /tmp:

(bash) tar zxfv /tmp/libstdc++-2.8.1.1.tar.gz
(bash) tar zxfv /tmp/libg++-2.8.1.1a.tar.gz
(bash) mv libg++-2.8.1.1a/* libstdc++-2.8.1.1

If you do not want libg++, just do not enter the last two commands.

Patches

You should apply at least the first patch; it is needed if you want to follow this step-by-step guide.

File Description
libstdc2811-p1.diff Correct tooldir configuration
libstdc2811-p2.diff Do not install libiberty

Compiling and installing the native library

I will assume you use bash as shell; if not, some commands may slightly differ. I will explain each step.

(bash) ./configure i486-pc-linux-gnulibc1 --prefix=/usr --enable-shared

We configure the library to live in /usr/... instead of /usr/local/.... Our (native) machine is a i486-pc-linux-gnulibc1 (strictly taken, you need not specify this as it is detected automatically). We also want the shared library.

(bash) make target_alias=i486-linux-libc5

This compiles the library. The target_alias is needed because a headerfile will be installed later on in /usr/i486-linux-libc5

(bash) make info

This generates the info-files.

(bash) make install target_alias=i486-linux-libc5

This installs the library. Remember you must be root to do this. If you want to know what will be installed, you can add prefix=/tmp/usr to install the files at a temporary location. Do not forget to do a proper installation afterwards!

(bash) make install-info

Install the info files. Remember you must be root to do this. If you want to know what will be installed, you can add prefix=/tmp/usr to install the files at a temporary location. Do not forget to do a proper installation afterwards!

Now check twice whether after a ldconfig all symbolic links point to the right library version. You have probably binaries lying around which are linked to libstdc++.so.27, which has a larger major number than the just installed libstdc++.so.2.8. With a recent version of the ld.so package, all should be well, but to make sure, things should be as follows:

(bash) (bash) ls -al /usr/lib/libstdc++.* | cut -c 65-
libstdc++.a
libstdc++.so -> libstdc++.so.2.8.1.1
libstdc++.so.2.8 -> libstdc++.so.2.8.1.1
libstdc++.so.2.8.1.1
libstdc++.so.27 -> libstdc++.so.27.2.8
libstdc++.so.27.2.8

Things should be exactly the same for libg++.*.

Compiling and installing the cross-library

I will assume you use bash as shell; if not, some commands may slightly differ. I will explain each step.

(bash) make distclean

Remove the stuff from the previous compile.

(bash) export PATH="/usr/i486-linux-libc6/bin:$PATH"

Enter the glibc-2 compilation environment.

(bash) ./configure i486-pc-linux-gnu \
--prefix=/usr/i486-linux-libc6 --enable-shared

We configure the library to live in /usr/i486-linux-libc6/... instead of /usr/local/.... This library is for a i486-pc-linux-gnu machine (strictly taken, you need not specify this as it is detected automatically). We also want the shared library.

(bash) make target_alias=i486-linux-libc6

This compiles the library.

(bash) (bash) make install target_alias=i486-linux-libc6

This installs the library. Remember you must be root to do this. If you want to know what will be installed, you can add prefix=/tmp/usr to install the files at a temporary location. Do not forget to do a proper installation afterwards!

(bash) rm -f /usr/i486-linux-libc6/man/gperf.1
(bash) rm -f /usr/i486-linux-libc6/bin/gperf

This is optional, but the installed man-pages are just duplicates of those installed for the native library, and gperf is the same for native and cross-compilers. Note that you do need seperate versions of genclass.

Checking the installation

Try to compile a small test-program. This one (hello.cc) for example:

#include <stream.h>
#include <string>
string s1 = "Hello";
string s2 = " world!\n";
main()
{
  cout << s1 << s2 ;
}

(bash) export "PATH=/usr/i486-linux-libc5/bin:$PATH"
(bash) g++ hello.cc -o hello
(bash) ldd hello
    libstdc++.so.2.8 => /usr/lib/libstdc++.so.2.8 (0x4000a000)
    libm.so.5 => /lib/libm.so.5 (0x40052000)
    libc.so.5 => /lib/libc.so.5 (0x4005b000)
(bash) ./hello
Hello world!
(bash) export "PATH=/usr/i486-linux-libc6/bin:$PATH"
(bash) g++ hello.cc -o hello
(bash) /usr/bin/ldd hello
    libstdc++.so.2.8 => /usr/i486-linux-libc6/lib/libstdc++.so.2.8 (0x40002000)
    libm.so.6 => /usr/i486-linux-libc6/lib/libm.so.6 (0x40049000)
    libc.so.6 => /usr/i486-linux-libc6/lib/libc.so.6 (0x40064000)
    /lib/ld-linux.so.2 => /usr/i486-linux-libc6/lib/ld-linux.so.2 (0x00000000)
(bash) ./hello
Hello world!

Note that the first change to PATH is unnecessary if you have not changed the path to the glibc-2 environment.

You can find a manifest of all installed files here.