问题描述
我使用 stack new demo
启动了一个新的堆栈项目,并在 apps 文件夹中定义了第二个文件 Other.hs
。没有依赖关系,只是:
module Other where
main :: IO ()
main = print 4
并在package.yaml
下的executables
中添加
other-exe:
main: Other.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- debug-multiple-files
现在当我执行 stack build
时,我得到:
<no location info>: error:
output was redirected with -o,but no output will be generated
because there is no Main module.
所以我将 -main-is
添加到 ghc-options:
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -main-is Other
现在 stack build
有效,但在 stack-ghci
上,在选择了我得到的其中一个可执行文件后:
<no location info>: error:
module ‘main:Main’ is defined in multiple files: /home/.../demo/app/Main.hs
/home/.../demo/app/Main.hs
Failed,no modules loaded.
解决方法
正如这里所指出的:https://stackoverflow.com/a/61393123
将 other-modules: []
添加到每个可执行文件块会有所帮助。
所以最后一个块是:
other-exe:
main: Other.hs
other-modules: []
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -main-is Other
dependencies:
- demo