首页 文章

使用c和stack / cabal编译Haskell包

提问于
浏览
0

有一个包装剪刀http://hackage.haskell.org/package/clipper,我想用它来检测复杂多边形的交集 . 它是C包的FFI . 如果你跑,它工作正常

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提议的Setup.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 回答

  • 0

    试试这个更简单的自定义Setup.hs文件:

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

    Original Answer

    一些想法:

    (1)创建一个名为 gcc 的包装器脚本,调用 g++ . 将脚本尽早放入PATH中,以便运行 gcc 将运行您的脚本而不是真正的 gcc . 也许只有在构建clipper包时才有这个包装脚本 .

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

    • 将clipper.cabal文件中的 build-type 字段修改为 Custom 而不是 Simple

    • 将Setup.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'
    

    注意:不需要导入Text.Show.Pretty,因此如果没有安装它,可以删除它和ppShow调用 .

    以上Setup.hs应与使用 --with-gcc=g++ 调用cabal具有相同的效果 .

相关问题