代码之家  ›  专栏  ›  技术社区  ›  Tristan

使用c++和stack/cabal编译Haskell包

  •  1
  • Tristan  · 技术社区  · 8 年前

    有一个包裹剪 http://hackage.haskell.org/package/clipper

    cabal build --with-gcc=/usr/bin/g++

    但并非如此。有什么方法可以将gcc选项放入cabal文件中,或者让我的堆栈项目用g++构建依赖项吗?

    由于某些原因设置$PATH不起作用:

    %  cabal build --with-gcc=g++
    Building clipper-0.0.1...
    Preprocessing library clipper-0.0.1...
    [1 of 1] Compiling Algebra.Clipper  ( dist/build/Algebra/Clipper.hs, dist/build/Algebra/Clipper.o )
    In-place registering clipper-0.0.1...
    
    %  PATH=$(pwd):$PATH gcc
    g++: fatal error: no input files
    compilation terminated.
    
    %  PATH=$(pwd):$PATH cabal build 
    Building clipper-0.0.1...
    Preprocessing library clipper-0.0.1...
    In file included from Clipper.hsc:27:0:
    cbits/clipper.hpp:29:18: fatal error: vector: Dosiero aÅ­ dosierujo ne ekzistas
    compilation terminated.
    compiling dist/build/Algebra/Clipper_hsc_make.c failed (exit code 1)
    command was: /usr/bin/gcc -c dist/build/Algebra/Clipper_hsc_make.c -o dist/build/Algebra/Clipper_hsc_make.o -fno-stack-protector -D__GLASGOW_HASKELL__=710 -Dlinux_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Icbits -Idist/build/autogen -include dist/build/autogen/cabal_macros.h -I/usr/local/haskell/ghc-7.10.2-x86_64/lib/ghc-7.10.2/base_GDytRqRVSUX7zckgKqJjgw/include -I/usr/local/haskell/ghc-7.10.2-x86_64/lib/ghc-7.10.2/integ_2aU3IZNMF9a7mQ0OzsZ0dS/include -I/usr/local/haskell/ghc-7.10.2-x86_64/lib/ghc-7.10.2/include -I/usr/local/haskell/ghc-7.10.2-x86_64/lib/ghc-7.10.2/include/
    

    同样,更改设置。下面@ErikR建议的hs没有帮助。

    % runghc Setup.hs build
    "Hello, I am running"
    fomg
    BuildFlags
      { buildProgramPaths = []
      , buildProgramArgs = []
      , buildDistPref = Flag "dist"
      , buildVerbosity = Flag Normal
      , buildNumJobs = NoFlag
      , buildArgs = []
     }
    fimg
    BuildFlags
      { buildProgramPaths = [ ( "gcc" , "/usr/bin/g++" ) ]
      , buildProgramArgs = []
      , buildDistPref = Flag "dist"
      , buildVerbosity = Flag Normal
      , buildNumJobs = NoFlag
      , buildArgs = []
      }
    Building clipper-0.0.1...
    Preprocessing library clipper-0.0.1...
    In file included from Clipper.hsc:27:0:
    (etc)
    

    请注意,它在buildHook行崩溃,因此为了打印标志,我需要改变顺序。

    1 回复  |  直到 8 年前
        1
  •  0
  •   ErikR    8 年前

    尝试这个更简单的自定义设置。hs文件:

    import Distribution.Simple
    import System.Environment
    
    main = do
      args <- getArgs
      defaultMainArgs $ ["--with-gcc=c++"] ++ args
    

    原始答案

    一些想法:

    (1) 创建名为 gcc 它调用 g++ 。将脚本放在PATH的早期,以便运行 海湾合作委员会 将运行您的脚本而不是真实的 海湾合作委员会 。可能只有在构建裁剪器包时才有这个包装器脚本。

    (2) 编写自定义Setup.hs。

    1. 修改 build-type Custom 而不是 Simple
    2. 更换安装程序。hs文件:

      import Distribution.Simple
      import Distribution.Simple.Setup
      import Distribution.Simple.LocalBuildInfo
      import Distribution.PackageDescription
      import Text.Show.Pretty
      
      main = do
        let hooks = simpleUserHooks
      
            myBuild :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO ()
            myBuild pkgd buildinfo uhooks flags = do
              putStrLn $ ppShow flags
              let flags' = flags { buildProgramPaths = [("gcc","g++")] ++ (buildProgramPaths flags) }
              buildHook hooks pkgd buildinfo uhooks flags'
              putStrLn $ ppShow flags'
            hooks' = hooks { buildHook = myBuild }
      
        defaultMainWithHooks hooks'
      

    上述设置。hs应具有与呼叫阴谋集团相同的效果 --with-gcc=g++ .