2016-08-05 66 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