[英]Compiling Haskell package using c++ and stack/cabal
我想使用一个打包程序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行崩溃,因此为了打印标志,我需要更改顺序。
试试下面这个简单的自定义Setup.hs文件:
import Distribution.Simple
import System.Environment
main = do
args <- getArgs
defaultMainArgs $ ["--with-gcc=c++"] ++ args
原始答案
一些想法:
(1)创建一个名为gcc
的包装器脚本,该包装器调用g++
。 将脚本放在PATH的早期,以便运行gcc
可以运行脚本而不是实际的gcc
。 也许只有在构建Clipper包时,才具有此包装器脚本。
(2)编写一个自定义的Setup.hs。
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具有相同的效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.