2013-01-09 48 views
16

用下面的项目结构:生产从单个项目的多个可执行文件

src/FirstExecutable.hs 
src/SecondExecutable.hs 
my-amazing-project.cabal 

和下面的小集团设置:

name:    my-amazing-project 
version:   0.1.0.0 
build-type:   Simple 
cabal-version:  >=1.8 

executable first-executable 
    hs-source-dirs: src 
    main-is:   FirstExecutable.hs 
    ghc-options:  -O2 -threaded -with-rtsopts=-N 
    build-depends: base == 4.5.* 

executable second-executable 
    hs-source-dirs: src 
    main-is:   SecondExecutable.hs 
    ghc-options:  -O2 -threaded -with-rtsopts=-N 
    build-depends: base == 4.5.* 

运行cabal install失败,并输出如下:

Installing executable(s) in 
/Users/mojojojo/Library/Haskell/ghc-7.4.2/lib/my-amazing-project-0.1.0.0/bin 
cabal: dist/build/second-executable/second-executable: does not exist 
Failed to install my-amazing-project-0.1.0.0 
cabal: Error: some packages failed to install: 
my-amazing-project-0.1.0.0 failed during the final install step. The exception 
was: 
ExitFailure 1 

我做错了什么,或者这是一个Cabal错误?是


所述可执行模块的内容如下:

module FirstExecutable where 

main = putStrLn "Running FirstExecutable" 

module SecondExecutable where 

main = putStrLn "Running SecondExecutable" 
+0

它适用于我。 – Satvik

+0

@Satvik我刚刚发现了解决方案。发布它 –

+2

你不应该在可执行文件中使用'module ..'。或者你可以使用'模块主' – Satvik

回答

19

小集团预计可执行的模块是Main。您应该跳过模块行或使用module Main where

好的,这里是可能的原因。当您实际编译程序时,如果模块不是Main,则不会生成haskell程序的可执行文件。运行可执行文件时使用Main模块的main功能。 ghc可能的解决方法是-main-is标志。所以你可以像

name:    my-amazing-project 
version:   0.1.0.0 
build-type:   Simple 
cabal-version:  >=1.8 

executable first-executable 
    hs-source-dirs: src 
    main-is:   FirstExecutable.hs 
    ghc-options:  -O2 -threaded -with-rtsopts=-N -main-is FirstExecutable 
    build-depends: base == 4.5.* 

executable second-executable 
    hs-source-dirs: src 
    main-is:   SecondExecutable.hs 
    ghc-options:  -O2 -threaded -with-rtsopts=-N -main-is SecondExecutable 
    build-depends: base == 4.5.* 
+1

是的,这正是我花了几个小时在谷歌上搜索并殴打自己后意外发现的。坦率地说,我很沮丧,他们为什么选择这样一个混乱的行为。一个糟糕的设计决定IMO –

+4

@NikitaVolkov此行为由[语言标准](http://www.haskell.org/onlinereport/modules.html)强制执行 - “Haskell程序是模块的集合,其中之一,按惯例,必须称为Main,并且必须输出价值主体。“ –

+0

@NikitaVolkov你可以在更新的答案中看到我建议的可能的解决方法。 – Satvik

相关问题