Jump to Navigation

Libc++

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:

tar zxfv /tmp/libstdc++-2.8.1.1.tar.gz
tar zxfv /tmp/libg++-2.8.1.1a.tar.gz
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.

  • Correct tooldir configuration
    This patch sets the correct tooldir if we change the target_alias.
  • (Optional) Do not install libiberty
    This patch disables the installation of libiberty, for two reasons: First, we already have it installed after compiling binutils, and second, it installs itself into the tooldir (/usr/i486-linux-libc5), where it does not belong.

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.

./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.

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

make info

This generates the info-files.

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!

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, check the output of 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.

make distclean

Remove the stuff from the previous compile.

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

Enter the glibc-2 compilation environment.

./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.

make target_alias=i486-linux-libc6

This compiles the library.

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!

rm -f /usr/i486-linux-libc6/man/gperf.1
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 separate 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()hello.cc
{
  cout << s1 << s2 ;
}

Compile it as follows for libc5:

export "PATH=/usr/i486-linux-libc5/bin:$PATH"
g++ hello.cc -o hello

Check the libraries it is linked again with 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)

Run it with ./hello.

Now compile it against libc6:

export "PATH=/usr/i486-linux-libc6/bin:$PATH"
g++ hello.cc -o hello

Check the libraries it is linked again with 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)

Run it with ./hello.

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 below.



Historic_content | by Dr. Radut