从单个项目生成多个可执行文件

时间:2013-01-09 15:31:48

标签: haskell cabal

使用以下项目结构:

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 bug?


可执行模块的内容如下:

module FirstExecutable where

main = putStrLn "Running FirstExecutable"

module SecondExecutable where

main = putStrLn "Running SecondExecutable"

1 个答案:

答案 0 :(得分:22)

cabal期望可执行文件的模块为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.*