0

我开始一个新的堆栈项目,stack new demo并在应用程序文件夹中定义了第二个文件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.
4

1 回答 1

1

正如这里所指出的: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
于 2021-01-24T00:09:21.587 回答