Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Dealing with C++11 support #22453

Closed
manphiz opened this issue Sep 11, 2013 · 12 comments
Closed

Dealing with C++11 support #22453

manphiz opened this issue Sep 11, 2013 · 12 comments
Labels

Comments

@manphiz
Copy link
Contributor

manphiz commented Sep 11, 2013

Homebrew needs a way to handle C++11 support systematically. Different compilers use different flags/lib for C++11 support, which makes things even more complicated.

The C++11 support in different compiler can be summarized as following:

  • llvm-gcc: no
  • apple-gcc-4.2: no
  • apple clang: through system libc++, but default to use libstdc++ in xcode 4.6.x and below.
    (It looks like 5.0 will default to libc++)
  • gcc-4.8+: through its own libstdc++. ABI incompatible with other C++ stdlibs.
  • clang-3.3+: it can use system libc++, or its own libc++. The latter needs complicated compiler flags combination to work.

With stdlib tracking work by @mistydemeo it is possible to distinguish which stdlib is in use. Tracking C++11 support may be needed as well, and may be done using options.

To enable C++11 support:

  • apple clang: clang++ -std=c++11 -stdlib=libc++
  • gcc-4.8+: g++-4.8 -std=c++11
  • clang-3.3+: clang++-3.3 -std=c++11 -stdlib=libc++. This will use system libc++. To use its own libc++, the command looks like
    clang++-3.3 -std=c++11 -stdlib=libc++ -nostdlibc++ -I/usr/local/lib/llvm-3.3/c++/v1 -L/usr/local/lib/llvm-3.3/usr/lib -lc++.

Packages built against different stdlib, or same stdlib with different C++ standard support, are incompatible. Formula using C++ may need to track whether its dependency is built using C++11 or not, and attempt to build using the same standard switch.

For adding switch, I'm more fund of just changing ENV.cxx, as modifying flags may interfere with other compilers. For instance, LDFLAGS with -stdlib=libc++ will cause problem when linking fortran executable (e.g. openmpi). Meanwhile, INCLUDE and LIBS should be handled separately.

@mistydemeo
Copy link
Member

...same stdlib with different C++ standard support

This is one case that the current stdlib tracking doesn't take care of. It needs to be added.

We also need to look at adding a new, convenient single DSL command to indicate that a formula requires C++11 and which generates the appropriate fails_with statements.

Do you know which Apple clang build is necessary for C++11 support?

@jacknagel
Copy link
Contributor

apple clang: through system libc++, but default to use libstdc++ in xcode 4.6.x and below. (It looks like 5.0 will default to libc++)
gcc-4.8+: through its own libstdc++. ABI incompatible with other C++ stdlibs.

Is the libstdc++ used by gcc-4.8+ ABI compatible with the one in clang from Xcode <= 4.6?

@manphiz
Copy link
Contributor Author

manphiz commented Sep 11, 2013

Do you know which Apple clang build is necessary for C++11 support?

Full C++11 support is ready for clang 3.3, which apple clang 5.0 is based on. Not sure about clang 3.2, but most software support it as well.

@manphiz
Copy link
Contributor Author

manphiz commented Sep 11, 2013

Is the libstdc++ used by gcc-4.8+ ABI compatible with the one in clang from Xcode <= 4.6?

No. Upstream GCC uses libsupc++, while libstdc++ shipped by Apple is (IIRC) ported to build upon libc++abi, so that it is compatible across apple gcc, llvm-gcc, and clang.

@MikeMcQuaid
Copy link
Member

Perhaps a crazy suggestion but instead of tracking and rebuilding this stuff (which seems like a nightmare) I'd suggest just deciding on a single item from that list we support on each OS. e.g. 10.9 and up (or 10.8/7 if they supports Xcode 5), system Clang and system libc++, 10.6 and below always use either gcc-4.8 or Homebrew clang and libc++ (whichever seems to work better). I don't think it's a good idea to be chopping and changing per package.

@mistydemeo
Copy link
Member

I don't think there is a single thing we can choose for everything. Some C++11 packages are going to need GNU GCC, for example, even on newer OSs. And, if I'm reading right, @manphiz says that different revisions of the C++ standard aren't intercompatible either - something using an older version of C++ won't be compatible with something building for C++11.

@MikeMcQuaid
Copy link
Member

Ok. We can certainly pick a stdlib to use as standard per-compiler though. I'm also not sure there will be (m)any projects we want to support where they won't work with the Clang in Xcode 5 and only the latest GCC.

@rolk
Copy link

rolk commented Sep 12, 2013

Formula using C++ may need to track whether its dependency is built using C++11 or not, and attempt to build using the same standard switch.

Also consider this: Boost built with libc++ cannot be used in programs otherwise linked with libstdc++ and vice versa. Programs built with -std=c++11 cannot use Apple's libstdc++. So; if you have two programs, one that must use C++11 and one that can not use it, and they both use Boost, then you have an uninstallable set.

One idea is to have a boost package that uses libc++ and a keg-only boost-libstdc++ that older programs can use, but this will create duplicates for many libraries that will have to be dragged around until everything is upgraded.

@MikeMcQuaid
Copy link
Member

I don't see how this is drastically different to the problem we have with universal. At least a first pass should handle it the same way (have an ENV, have a special option which sets things up and stores state in the tab which can be queried by dependencies).

@rolk We're not going to be creating duplicate packages.

@mistydemeo
Copy link
Member

I've pushed a few commits which improve the C++ stdlib tracking, namely:

  • Tabs now actually record the C++ stdlib used, and stdlib tracking correctly deals with formulae which don't install any C++ objects. This way Homebrew will allow formulae built under different compilers as dependencies if only one (or none) link to a C++ stdlib.
  • Fixed up assumptions about what the C++ stdlib is. Homebrew now assumes that software being built using clang on 10.9 or newer is being built using libc++, and otherwise assumes it's using libstdc++.

We still need to standardize a way for users to request what C++ stdlib to use when building with clang, so that we can track a) software on 10.7 and 10.8 being built against libc++ using clang, and b) software on 10.9+ building against libstdc++ using clang.

@staticfloat
Copy link
Contributor

I've got a bunch of bottles built on 10.8 that work on 10.6-10.8, but don't work on 10.9, due to the incorrect stdlib. Is there an option I can pass my 10.8 build machine to link against the "correct" stdlib for 10.9, or is there no stdlib that will work from 10.6-10.9? Thanks!

@manphiz
Copy link
Contributor Author

manphiz commented Oct 26, 2013

@staticfloat Your issue is not related to this PR. Please open a new issue instead.

mistydemeo added a commit to mistydemeo/homebrew that referenced this issue Dec 4, 2013
This allows formulae to declare requirements on standards like C++11
or OpenMP, and automatically fills in the fails_with statements for
compilers that don't support it.

Partial solution for the features needed in Homebrew#22453.
mistydemeo added a commit to mistydemeo/homebrew that referenced this issue Dec 4, 2013
This allows formulae to declare requirements on standards like C++11
or OpenMP, and automatically fills in the fails_with statements for
compilers that don't support it.

Partial solution for the features needed in Homebrew#22453.
ehershey pushed a commit to ehershey/homebrew that referenced this issue Apr 4, 2014
* Add options and ENV method to specify building in C++11 mode.
  - Set C++ compiler flags to enable C++11 mode.
  - To add options to support C++11 mode, a formula can now use

      option :cxx11

    to provide "--c++11" option, and detect and enable C++11 support in
    install method using

      ENV.cxx11 if build.cxx11?

Closes Homebrew#22453.
@Homebrew Homebrew locked and limited conversation to collaborators Feb 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants