Github actions fail for Mac with my Haskell package including C++ --- how to enable C++11 for Mac?

I have some Github actions for my library 'numerical-integration'. They all work fine except those on Mac. Among the warnings and error messages for Mac, there are:

I don't understand since I have in my cabal file:

  extra-libraries:     stdc++
  ghc-options:         -optcxx-std=c++11
  cxx-options:         -fPIC -std=c++11

I also get this error:

/Users/runner/work/numerical-integration/numerical-integration/cpp/integration.cpp:30:38: error:
     error: expected expression
      std::function<double(double)> f_ = [&](double x) { return f(x); };

Some of you recommend me to not use a lambda function in my previous post. But again, I'm not fluent in C/C++ and I do what I can, and I'm happy as long as it works... And the library works very well. But I'm ok for changing something if I understand.

Is there something special to do in the Cabal file for Mac ? I googled "cabal mac c++11" but I found nothing.

I tried this but that does not change anything:

  if os(darwin)
    cxx-options:       -fPIC -std=gnu++11
    cxx-options:       -fPIC -std=c++11


  • I've found a way. This works for Mac systems with a recent enough ghc (about >=9.4):

      hs-source-dirs:      src
      exposed-modules:     Numerical.Integration
      build-depends:       base >= 4.7 && < 5
      if impl(ghc >= 9.4)
        build-depends:     system-cxx-std-lib == 1.0
      elif os(darwin) || os(freebsd)
        extra-libraries:   c++11
        extra-libraries:   stdc++
      other-extensions:    ForeignFunctionInterface
      include-dirs:        cpp
      C-sources:           cpp/integration.cpp
      install-includes:    cpp/ComputeGaussKronrodNodesWeights.h
                         , cpp/Eigen/Cholesky
                         , ............
                         , cpp/Piessens.h  
      default-language:    Haskell2010
      ghc-options:         -Wall
      if os(darwin) || os(freebsd)
        ghc-options:       -optcxx-stdlib=libc++

    The key ingredient is the package system-cxx-std-lib == 1.0.