5.6. Libstdc++ from GCC-16.1.0

#### Linux From Scratch - Version r13.0-154-systemd

### Chapter 5. Compiling a Cross-Toolchain

- Prev

  Glibc-2.43

- Next

  Cross Compiling Temporary Tools

- Up
- Home

# 5.6. Libstdc++ from GCC-16.1.0

Libstdc++ is the standard C++ library. It is needed to compile C++ code (part of GCC is written in C++), but we had to defer its installation when we built gcc-pass1 because Libstdc++ depends on Glibc, which was not yet available in the target directory.

Approximate build time: 0.2 SBU
Required disk space: 1.3 GB

## 5.6.1. Installation of Target Libstdc++

### Note

Libstdc++ is part of the GCC sources. You should first unpack the GCC tarball and change to the `gcc-16.1.0` directory.

Create a separate build directory for Libstdc++ and enter it:

    mkdir -v build
    cd       build

Prepare Libstdc++ for compilation:

    ../libstdc++-v3/configure      \
        --host=$LFS_TGT            \
        --build=$(../config.guess) \
        CXX=$LFS_TGT-gcc           \
        --prefix=/usr              \
        --disable-multilib         \
        --disable-nls              \
        --disable-libstdcxx-pch    \
        --with-gxx-include-dir=/tools/$LFS_TGT/include/c++/16.1.0

The meaning of the configure options:

`--host=...`

  Specifies that the cross-compiler we have just built should be used instead of the one in `/usr/bin`.

`CXX=$LFS_TGT-gcc`

  Specifies to use $LFS_TGT-gcc to compile the C++ code. The default, $LFS_TGT-g++, would automatically specify linking against `libstdc++` when invoking the linker, but in our case `libstdc++` is not installed yet so some checks in the configure script would misbehave with $LFS_TGT-g++. In a normal build, this override is automatically passed to the configure script from the top level directory. Here we explicitly pass it.

`--disable-libstdcxx-pch`

  This switch prevents the installation of precompiled include files, which are not needed at this stage.

`--with-gxx-include-dir=/tools/$LFS_TGT/include/c++/16.1.0`

  This specifies the installation directory for include files. Because Libstdc++ is the standard C++ library for LFS, this directory should match the location where the C++ compiler ($LFS_TGT-g++) would search for the standard C++ include files. In a normal build, this information is automatically passed to the Libstdc++ configure options from the top level directory. In our case, this information must be explicitly given. The C++ compiler will prepend the sysroot path `$LFS` (specified when building GCC-pass1) to the include file search path, so it will actually search in `$LFS/tools/$LFS_TGT/include/c++/16.1.0`. The combination of the `DESTDIR` variable (in the make install command below) and this switch causes the headers to be installed there.

Compile Libstdc++ by running:

    make

Install the library:

    make DESTDIR=$LFS install

Remove the libtool archive files because they are harmful for cross-compilation:

    rm -v $LFS/usr/lib/lib{stdc++{,exp,fs},supc++}.la

Details on this package are located in Section 8.32.2, “Contents of GCC.”

- Prev

  Glibc-2.43

- Next

  Cross Compiling Temporary Tools

- Up
- Home