【发布时间】:2020-04-02 01:17:05
【问题描述】:
我正在尝试使用 Cabal 构建 a Haskell project。我有一个文件 src/Main.hs,其中包含模块 Main 和函数 main。该文件运行我的应用程序的 Web 界面。我还有另一个文件 src/CLI.hs,其中包含模块 CLI 和函数 main。我可以使用runhaskell CLI ... 很好地运行它,但我似乎无法使用 cabal 编译它。
问题是,即使我将 CLI.hs 指定为主文件 (main-is: CLI.hs),它仍然会使用来自 src/Main.hs 的 main 编译项目,从而为我提供 Web 应用程序而不是命令行界面。
我希望能够编译两个可执行文件,一个是 Web 应用程序,一个是 CLI,在 CLI.hs 中将每个的入口点指定为 main,在 Main.hs 中指定为 main,分别。
这是我目前正在使用的 .cabal 文件的片段:
executable color-word-analyzer-cli
main-is: CLI.hs
other-modules: AnnotateColors
, CategorizeColor
, ColorMaps
, FindColors
, PlotColors
, Types
, Main
build-depends: base
, lucid
...
, wai-middleware-static
hs-source-dirs: src/
default-language: Haskell2010
executable color-word-analyzer-web
main-is: Main.hs
other-modules: AnnotateColors
, CategorizeColor
, ColorMaps
, FindColors
, PlotColors
, Types
, CLI
build-depends: base
, lucid
...
, wai-middleware-static
hs-source-dirs: src/
default-language: Haskell2010
哪个会引发错误(以及其他):
Building executable 'color-word-analyzer-cli' for color-word-analyzer-0.1.0.0..
Warning: Enabling workaround for Main module 'Main' listed in 'other-modules'
illegally!
<no location info>: warning: [-Wmissing-home-modules]
These modules are needed for compilation but not listed in your .cabal file's other-modules:
Main
这很有趣,因为Main 清楚地列在other-modules 中。
我使用的是 cabal 版本 3.0.0.0 和 ghc 版本 8.8.2。
【问题讨论】: