2016-08-05 70 views
0

我想用一个软件包剪辑器http://hackage.haskell.org/package/clipper来检测复杂多边形的交集。这是一个C++包的FFI。如果您运行使用C++和stack/cabal编译Haskell软件包

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/ 

同样,改变Setup.hs建议,由@ErikR下面没有帮助。

% 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行崩溃,所以为了获得打印标志,我需要改变周围的顺序。

回答

0

试试这个简单的定制Setup.hs文件:

import Distribution.Simple 
import System.Environment 

main = do 
    args <- getArgs 
    defaultMainArgs $ ["--with-gcc=c++"] ++ args 

原来的答案

一些想法:

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

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

  1. 修改build-type字段中clipper.cabal文件是Custom,而不是Simple
  2. 更换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' 
    

注:文字的进口.Show.Pretty不是必需的,所以如果你没有安装它,你可以删除它和ppShow调用。

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

+0

不幸的是您的解决方案无法正常工作。我在我的问题中添加了一些评论来描述我的经历。 – Tristan

+0

谢谢,这个更简单的提案有效。 – Tristan