mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-09-01 21:24:42 +00:00
Two halves of how the compiler finds libstdc++.
The library was not on the link path. `wrapCCWith` was given
`libcxx = libstdcxx`, which tells cc-wrapper where the C++ headers live
but does not put the library where a GNU compiler looks, so every C++
link failed with `cannot find -lstdc++`. Add `-B${libstdcxx}/lib`, as
libgcc, libssp, libatomic and libgomp already are.
The headers had the opposite problem: found too eagerly, by the wrong
language. libstdc++ deliberately ships headers named after C headers --
`math.h`, `stdlib.h`, `complex.h`, `stdckdint.h`, `stdbit.h`,
`stdatomic.h`, `tgmath.h`, `fenv.h` -- whose purpose is to shadow the C
ones when compiling C++. Installed into `$dev/include` they shadowed
unconditionally, since `libcxx` is a propagated target-target dep of
cc-wrapper and the setup hook puts that directory on the **C** include
path of everything built with the compiler. Under C, libstdc++'s
`<stdckdint.h>` is an empty shell, so its functions vanish:
bash: braces.c: implicit declaration of function 'ckd_sub'
coreutils: randperm.c: implicit declaration of function 'stdc_bit_width'
Both build fine with monolithic GCC, whose libstdc++ headers live in
`include/c++/$ver` and are added by the g++ driver alone. Install them
into a sibling `include-cxx`, which keeps them off C's include path while
staying findable for C++; no version or target subdirectory is needed,
since the store path already separates one libstdc++ from another.
Assisted-by: Claude Code (Claude Opus 5)
133 lines
5.1 KiB
Diff
133 lines
5.1 KiB
Diff
From db427c55334dd2edc11397d3a92d55dc9c06d1c3 Mon Sep 17 00:00:00 2001
|
|
From: John Ericson <git@JohnEricson.me>
|
|
Date: Sun, 20 Jul 2025 14:20:00 -0400
|
|
Subject: [PATCH] libstdc++: Force regular lib dir, headers in include-cxx
|
|
|
|
Delete a bunch of unneeded logic to do this.
|
|
|
|
The library goes straight in $(libdir), with no version-specific or
|
|
target-specific subdirectory.
|
|
|
|
The headers go in $(includedir)-cxx rather than $(includedir). libstdc++
|
|
intentionally ships headers named after C headers -- `math.h`, `stdlib.h`,
|
|
`complex.h`, `stdckdint.h` and friends -- whose whole purpose is to shadow
|
|
the C ones when compiling C++. Installed into the ordinary include dir they
|
|
shadow them when compiling *C* too, because the generic setup hook puts that
|
|
directory on the C include path. A sibling directory keeps them out of C's
|
|
way while staying findable for C++; no version or target subdirectory is
|
|
needed, since the store path already separates one libstdc++ from another.
|
|
---
|
|
libstdc++-v3/acinclude.m4 | 80 ++------------------------------
|
|
libstdc++-v3/include/Makefile.am | 2 +-
|
|
2 files changed, 4 insertions(+), 78 deletions(-)
|
|
|
|
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
|
|
index a0094c2dd95..a0718dff394 100644
|
|
--- a/libstdc++-v3/acinclude.m4
|
|
+++ b/libstdc++-v3/acinclude.m4
|
|
@@ -727,85 +727,11 @@ dnl
|
|
dnl This logic must match gcc/configure.ac's setting of gcc_gxx_include_dir.
|
|
dnl config/gxx-include-dir.m4 must be kept consistant with this as well.
|
|
AC_DEFUN([GLIBCXX_EXPORT_INSTALL_INFO], [
|
|
- glibcxx_toolexecdir=no
|
|
- glibcxx_toolexeclibdir=no
|
|
+ glibcxx_toolexecdir='$(libdir)'
|
|
+ glibcxx_toolexeclibdir='$(libdir)'
|
|
+ gxx_include_dir='$(includedir)-cxx'
|
|
glibcxx_prefixdir=$prefix
|
|
|
|
- AC_MSG_CHECKING([for gxx-include-dir])
|
|
- AC_ARG_WITH([gxx-include-dir],
|
|
- AC_HELP_STRING([--with-gxx-include-dir=DIR],
|
|
- [installation directory for include files]),
|
|
- [case "$withval" in
|
|
- yes) AC_MSG_ERROR([Missing directory for --with-gxx-include-dir]) ;;
|
|
- no) gxx_include_dir=no ;;
|
|
- *) gxx_include_dir=$withval ;;
|
|
- esac],
|
|
- [gxx_include_dir=no])
|
|
- AC_MSG_RESULT($gxx_include_dir)
|
|
-
|
|
- AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
|
|
- AC_ARG_ENABLE([version-specific-runtime-libs],
|
|
- AC_HELP_STRING([--enable-version-specific-runtime-libs],
|
|
- [Specify that runtime libraries should be installed in a compiler-specific directory]),
|
|
- [case "$enableval" in
|
|
- yes) version_specific_libs=yes ;;
|
|
- no) version_specific_libs=no ;;
|
|
- *) AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
|
|
- esac],
|
|
- [version_specific_libs=no])
|
|
- AC_MSG_RESULT($version_specific_libs)
|
|
-
|
|
- GCC_WITH_TOOLEXECLIBDIR
|
|
-
|
|
- # Default case for install directory for include files.
|
|
- if test $version_specific_libs = no && test $gxx_include_dir = no; then
|
|
- gxx_include_dir='include/c++/${gcc_version}'
|
|
- if test -n "$with_cross_host" &&
|
|
- test x"$with_cross_host" != x"no"; then
|
|
- gxx_include_dir='${prefix}/${target_alias}/'"$gxx_include_dir"
|
|
- else
|
|
- gxx_include_dir='${prefix}/'"$gxx_include_dir"
|
|
- fi
|
|
- fi
|
|
-
|
|
- # Version-specific runtime libs processing.
|
|
- if test $version_specific_libs = yes; then
|
|
- # Need the gcc compiler version to know where to install libraries
|
|
- # and header files if --enable-version-specific-runtime-libs option
|
|
- # is selected. FIXME: these variables are misnamed, there are
|
|
- # no executables installed in _toolexecdir or _toolexeclibdir.
|
|
- if test x"$gxx_include_dir" = x"no"; then
|
|
- gxx_include_dir='${libdir}/gcc/${host_alias}/${gcc_version}/include/c++'
|
|
- fi
|
|
- glibcxx_toolexecdir='${libdir}/gcc/${host_alias}'
|
|
- glibcxx_toolexeclibdir='${toolexecdir}/${gcc_version}$(MULTISUBDIR)'
|
|
- fi
|
|
-
|
|
- # Calculate glibcxx_toolexecdir, glibcxx_toolexeclibdir
|
|
- # Install a library built with a cross compiler in tooldir, not libdir.
|
|
- if test x"$glibcxx_toolexecdir" = x"no"; then
|
|
- if test -n "$with_cross_host" &&
|
|
- test x"$with_cross_host" != x"no"; then
|
|
- glibcxx_toolexecdir='${exec_prefix}/${host_alias}'
|
|
- case ${with_toolexeclibdir} in
|
|
- no)
|
|
- glibcxx_toolexeclibdir='${toolexecdir}/lib'
|
|
- ;;
|
|
- *)
|
|
- glibcxx_toolexeclibdir=${with_toolexeclibdir}
|
|
- ;;
|
|
- esac
|
|
- else
|
|
- glibcxx_toolexecdir='${libdir}/gcc/${host_alias}'
|
|
- glibcxx_toolexeclibdir='${libdir}'
|
|
- fi
|
|
- multi_os_directory=`$CXX -print-multi-os-directory`
|
|
- case $multi_os_directory in
|
|
- .) ;; # Avoid trailing /.
|
|
- *) glibcxx_toolexeclibdir=$glibcxx_toolexeclibdir/$multi_os_directory ;;
|
|
- esac
|
|
- fi
|
|
-
|
|
AC_MSG_CHECKING([for install location])
|
|
AC_MSG_RESULT($gxx_include_dir)
|
|
|
|
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
|
|
index 537774c2668..c0bfeb43b44 100644
|
|
--- a/libstdc++-v3/include/Makefile.am
|
|
+++ b/libstdc++-v3/include/Makefile.am
|
|
@@ -1048,7 +1048,7 @@ endif
|
|
|
|
host_srcdir = ${glibcxx_srcdir}/$(OS_INC_SRCDIR)
|
|
host_builddir = ./${host_alias}/bits
|
|
-host_installdir = ${gxx_include_dir}/${host_alias}$(MULTISUBDIR)/bits
|
|
+host_installdir = ${gxx_include_dir}/bits
|
|
host_headers = \
|
|
${host_srcdir}/ctype_base.h \
|
|
${host_srcdir}/ctype_inline.h \
|
|
--
|
|
2.47.2
|
|
|