https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122409

            Bug ID: 122409
           Summary: -stdlib=libc++ doesn't work on musl
           Product: gcc
           Version: 14.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhixu.liu at gmail dot com
  Target Milestone: ---

# g++ -stdlib=libc++ -x c++ -E -P <(echo -e '#if __cplusplus >=
202002L\n#include <version>\n#else\n#include <ciso646>\n#endif\n#if
defined(_LIBCPP_VERSION)\nHAVE_LIBCXX\n#elif
defined(__GLIBCXX__)\nHAVE_LIBSTDCPP\n#endif')
/dev/fd/63:4:10: fatal error: ciso646: No such file or directory
compilation terminated.

This is found on Gentoo with musl profile. See bellow for details with -v,
"/usr/include/c++/v1" is not searched at all.

# g++ -v -stdlib=libc++ -x c++ -E -P <(echo -e '#if __cplusplus >=
202002L\n#include <version>\n#else\n#include <ciso646>\n#endif\n#if
defined(_LIBCPP_VERSION)\nHAVE_LIBCXX\n#elif
defined(__GLIBCXX__)\nHAVE_LIBSTDCPP\n#endif')
Using built-in specs.
COLLECT_GCC=g++
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-pc-linux-musl
Configured with:
/var/tmp/portage/sys-devel/gcc-14.3.1_p20250801/work/gcc-14-20250801/configure
--host=x86_64-pc-linux-musl --build=x86_64-pc-linux-musl --prefix=/usr
--bindir=/usr/x86_64-pc-linux-musl/gcc-bin/14
--includedir=/usr/lib/gcc/x86_64-pc-linux-musl/14/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/14
--mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/14/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/14/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/14/include/g++-v14
--disable-silent-rules --disable-dependency-tracking
--with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/14/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --disable-nls
--disable-libunwind-exceptions --enable-checking=release
--with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo
14.3.1_p20250801 p4' --with-gcc-major-version-only --enable-libstdcxx-time
--enable-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix
--enable-__cxa_atexit --disable-multilib --with-multilib-list=m64
--disable-fixed-point --enable-targets=all --enable-offload-defaulted
--enable-offload-targets=nvptx-none --enable-libgomp --disable-libssp
--disable-libada --disable-cet --disable-systemtap
--disable-valgrind-annotations --disable-vtable-verify --disable-libvtv
--with-zstd --without-isl --enable-default-pie --enable-host-pie
--enable-host-bind-now --enable-default-ssp --disable-fixincludes
--with-gxx-libcxx-include-dir=/usr/include/c++/v1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.3.1 20250801 (Gentoo 14.3.1_p20250801 p4)
COLLECT_GCC_OPTIONS='-v' '-stdlib=libc++' '-E' '-P' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-musl/14/cc1plus -E -quiet -v -P -D_GNU_SOURCE
/dev/fd/63 -mtune=generic -march=x86-64 -stdlib=libc++ -dumpbase 63
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-pc-linux-musl/14/../../../../x86_64-pc-linux-musl/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include
 /usr/lib/gcc/x86_64-pc-linux-musl/14/include
End of search list.
/dev/fd/63:4:10: fatal error: ciso646: No such file or directory
compilation terminated.

If I'm right, the reason is:

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/linux.h;h=d6280a4d4dd4d5fc05f07a7e38804b453591ea90;hb=HEAD#l179
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/cppdefault.cc;h=f98c39c53ec1a5650b8f94467d258f647cc27417;hb=HEAD#l39

INCLUDE_DEFAULTS is defined for musl in gcc/config/linux.h, so line 39 of
gcc/cppdefault.cc is true, causing
GPLUSPLUS_LIBCXX_INCLUDE_DIR ... is ignored (used only in #else).
i.e., for musl, g++ won't search /usr/include/c++/v1, unless specified by -I.

I choose the tested version only, the bug should exist for earlier version, and
current release too.

Reply via email to