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

            Bug ID: 80781
           Summary: Feature request: build option to use libc++ instead of
                    libstdc++ for increased usability on Mac
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rjvbertin at gmail dot com
  Target Milestone: ---

Created attachment 41366
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41366&action=edit
prototype use-libcxx.diff

Using G++ as a full-featured and generally usable C++ compiler on Mac OS X 10.9
and newer (and potentially other systems) requires using the libc++ runtime
instead of libstdc++. Instructions can be found online (e.g.
http://stackoverflow.com/questions/22228208/using-g-with-libc) on how to get
G++ to build code doing just that. The principle works fine but the method is a
bit too convoluted to use in anything but smallish projects.

I have thus been working on a patch for GCC 6.3.0 (latest release when I
started) that makes G++ behave according to those online instructions:
- use the /path/to/llvm-$version/include/c++/v1 include directory for the
standard C++ headers
- emit `-lc++ -lc++abi` instead of -lstdc++

This turned out far less hairy than I feared it might be though, a few details
aside. Not all system libc++ versions have `operator delete(void*, unsigned
long)` for instance, but it has turned out to be safe to use GCC's libsupc++ as
a source for that and possibly other methods.

The hairiest detail was probably figuring out the best way to build GCC itself
(also the costliest detail: each trial cost up to 1.5 hours rebuilding
everything from scratch). I'm now at a point where I can present a prototype
patch: it provides a few hooks (environment variables) to switch back to using
libstdc++ which are used during the GCC build process. The compiler itself is
thus built "as usual".

I have been able to build a few quite complex projects with the resulting
compiler; boost, KDevelop and digiKam (boost with a patch to remove the
presumption that only clang uses libc++). The resulting binaries function as if
they were built using clang++ and not with a compiler that normally uses
libstdc++.

The patch is a typical "distribution" patch, i.e. it is applied in a package
install variant and does not currently add a configure option to the build
system. When selected, GCC is configured and built with
`GCC_IS_BUILDING_ITSELF=1 GCC_FORCE_LIBSTDCPP=1` set in the environment.

Would there be any interest in incorporating this functionality properly, thus
making G++ officially an alternative C++ compiler on Mac (and possibly other
BSD systems)? Or are there too many pitfalls which I just haven't discovered
yet?

Reply via email to