11. libstdc++
libstdc++ is GCC’s C++ standard library. The cross GCC of Part II was built without it, because the library needs a C library and there was none. With musl in build/fs, this step builds it from the same GCC source, so that the C++ programs of the bootstrap, the native GCC among them, can be compiled and linked. This page shows the commands of script/phases/10_bootstrap/030_libstdc++.sh and explains each switch, including the one that puts its headers outside the root.
Source: the archive of the gcc port
Installs into: build/fs/usr/lib, and its headers into build/cross
Approximate build time: 1.4 SBU
Installation of libstdc++
GCC_SRC=$(extract_port_source gcc)
GCC_VER=$(get_port_version gcc)
cd "$GCC_SRC"
mkdir -p build && cd build
../libstdc++-v3/configure \
--host=$KDOS_TARGET \
--build=$(../config.guess) \
--prefix=/usr \
--disable-multilib \
--disable-nls \
--disable-libstdcxx-pch \
--with-gxx-include-dir=/../cross/$KDOS_TARGET/include/c++/$GCC_VER
make DESTDIR=$SYSROOT install
# Remove the libtool archive files because they are harmful for cross-compilation
rm -v $SYSROOT/usr/lib64/lib{stdc++{,exp,fs},supc++}.la
script/phases/10_bootstrap/030_libstdc++.sh, lines 24–43
get_port_version reads the gcc recipe’s version, which names GCC’s versioned header directory. The configure script run is the one in libstdc++-v3/, the library’s own directory inside the GCC source: only the library is built, not the compiler. make install builds what it installs, so no separate make comes first.
The meaning of the configure options
--host=$KDOS_TARGET-
The library runs on KDOS, so it is compiled by the cross compiler,
x86_64-kdos-linux-musl-g++, against musl. --build=$(../config.guess)-
The machine the build runs on, the container, as GCC’s own
config.guessnames it. --prefix=/usr-
Install the library under
/usr. --disable-multilib,--disable-nls- One ABI and no message catalogues, as for the cross compiler.
--disable-libstdcxx-pch- Do not build precompiled headers. They are large, and they only make C++ compiles faster.
--with-gxx-include-dir=/../cross/$KDOS_TARGET/include/c++/$GCC_VER-
Where the C++ headers go. Under
DESTDIR=$SYSROOTthe path becomesbuild/fs/../cross/x86_64-kdos-linux-musl/include/c++/<version>, which isbuild/cross/x86_64-kdos-linux-musl/include/c++/<version>: the directory in which the crossg++looks for its standard headers. The headers are for that compiler, so they go with it, and the root gets its own copy from the native GCC in step 100. The path works becausescript/env/host.envputsbuild/crossbesidebuild/fs.
Removing the libtool archives
The last command deletes the libtool archives, libstdc++.la, libstdc++exp.la, libstdc++fs.la and libsupc++.la. Each records paths from this build, which libtool would copy into every library later linked through it, and no package will ever own them, so nothing else would remove them (see Part III).
The path is /usr/lib64. Without the gcc port’s t-linux64-lib.patch, which only the native builds apply, GCC’s library directory on x86-64 is lib64. The fs/ copy of step 000 made /usr/lib64 a link to lib, so the files are in /usr/lib all the same. rm -v has no -f, so the step fails if any of the four is missing, which it would be only if the install had gone somewhere else.
Contents of libstdc++
Installed libraries: libstdc++.so and libstdc++.a, the C++ standard library; libsupc++.a, the language support half alone (exceptions, RTTI, new and delete); libstdc++exp.a and libstdc++fs.a, the experimental and filesystem extensions.
Installed headers: build/cross/x86_64-kdos-linux-musl/include/c++/<version>, outside the root, with the sources of the C++ std module, bits/std.cc and bits/std.compat.cc, among them.
Other files: libstdc++.modules.json in /usr/lib, the manifest that tells a compiler where the std module’s sources are; the libstdc++.so.6.*-gdb.py hook beside the library, which the native GCC step deletes; and the gdb pretty-printers in /usr/share/gcc-<version>/python.
Built again later
libstdc++ has no port of its own. It is built again as part of GCC, twice:
- The native GCC of step 100 builds it with the compiler and installs it into
build/fs, with its headers in/usr/include/c++/<version>in the root. - The gcc port, in
20_selfhost, does the same inside the chroot. It appliest-linux64-lib.patch, so its libraries go to/usr/libdirectly, andlibstdcxx-generic-locale-names.patch, sostd::locale("")accepts any locale name musl accepts instead of onlyCandPOSIX, and it moves thelibstdc++.so.6.*-gdb.pypretty-printer hook to/usr/share/gdb/auto-load/usr/lib, where gdb will load it. kpkg adopts the files this step installed in/usr/libas thegccpackage’s.
See also
- Part III: the bootstrap
- Cross GCC, pass 1: the compiler built without this library
- Native GCC: the compiler built with it
- Syncing fs/: why
/usr/lib64is a link tolib