0

I start a new stack project with stack new demo and define a second file Other.hs in the apps folder. There are no dependencies, just:

module Other where

main :: IO ()
main = print 4

And in package.yaml under executables I add

  other-exe:
    main:                Other.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - debug-multiple-files

Now when I do stack build I get:

<no location info>: error:
    output was redirected with -o, but no output will be generated
because there is no Main module.

So I add -main-is to ghc-options:

    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    - -main-is Other

Now stack build works, but on stack-ghci, after selecting one of the executables I get:

<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.
peer
  • 4,171
  • 8
  • 42
  • 73
  • Ugh. This seems like a shortcoming with stack; `main: Other.hs` really ought to be enough for it to know that it needs to pass `-main-is Other.hs` on its own. – Daniel Wagner Jan 24 '21 at 10:48

1 Answers1

3

As pointed out here: https://stackoverflow.com/a/61393123 adding other-modules: [] to each executables block helps. So the final block would be:

  other-exe:
    main:                Other.hs
    other-modules:       []
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    - -main-is Other
    dependencies:
    - demo
peer
  • 4,171
  • 8
  • 42
  • 73