Closed stephenpascoe closed 6 years ago
I realise -std=c++11
is needed to compile the enum class
statement because enum classes are a C++11 feature. So the question really is why does -std=c++11
cause compiling to fail when we use the $fun
anti-quoter in someFunc
but not when we compile someFunc2
?
After finding these related issues:
I tried building the source inside a docker container and it worked. The OSX compiler is more picky about what it allows.
I can work around this with the custom Setup.hs below. Unfortunately stack ghci
doesn't work but once you've built it you can comment out ghc-options
and run stack ghci
successfully.
import Distribution.Simple
import Distribution.Simple.Setup
import Distribution.Types.HookedBuildInfo
import Distribution.PackageDescription
import Distribution.Simple.LocalBuildInfo
import Data.List (dropWhile)
main = defaultMainWithHooks simpleUserHooks { buildHook = myBuildHook
}
BuildHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO ()
myBuildHook desc info hooks flags = (buildHook simpleUserHooks) (fixDescription desc) info hooks flags
-- Fix a PackageDescription to remove the -optc-std=c++11 option
fixDescription desc = desc { library = fmap fixLibrary (library desc) } where
fixLibrary lib = lib { libBuildInfo = fixBuildInfo (libBuildInfo lib) }
fixBuildInfo info = info { options = fixOptions (options info) }
fixOptions options = fmap fixOption options
fixOption (flavor, args) = (flavor, dropWhile ((==) "-optc-std=c++11") args)
It's going to be a bit easier in GHC 8.8: https://gitlab.haskell.org/ghc/ghc/issues/16477
I can't get inline-c-cpp to compile if I use the
funCtx
to try and call Haskell from C++. The problem seems to be I can't specify exactly when to use the "-std=c++11" switch in Cabal.Below is a minimal file which exposes the problem. My system is:
src/Lib.hs
package.yaml
If I compile without -std=c++11 I get
error: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
If I compile with -std=c++11 I getStrangely
someFunc2
will compile in either case.