1

Q: How to adjust cabal(stack?) settings so that app/LogAnalysis.hs is treated as main log after all?

Here is how I got myself this error:

  • Created new project with stack new xyz
  • Renamed app/Main.hs to app/LogAnalysis.hs
  • Adjusted main-is option in xyz.cabal file

Problem is I either entered that data somehow incorrectly or cabal ignores that new value. Here is error I get:

Preprocessing executable 'WeekTwo-exe' for WeekTwo-0.1.0.0...

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

Here is relevant entry in xyz.cabal

executable WeekTwo-exe
    hs-source-dirs:      app
    main-is:             LogAnalysis.hs
    ghc-options:         -threaded -rtsopts -with-rtsopts=-N
    build-depends:       base
                       , WeekTwo
    default-language:    Haskell2010

And module in question is:

module LogAnalysis where
import Log

main :: IO ()
main = print (parseMessage "I 29 la la")

Versions: Stack - Version 1.3.2 GHC - 7.15 Cabal - 1.24.0.0

PS if it's of any interest I'm doin 2nd week of Haskel course CIS 194.

przemo_li
  • 3,932
  • 4
  • 35
  • 60
  • GHC requires that the module that requires the main `main :: IO ()` is named `Main`. Modules must generally have a filepath that corresponds to the module name. You'll have to rename `LogAnalysis.hs` to `Main.hs` again. – sjakobi Jan 13 '17 at 21:03
  • Isn't `main-is` supposed to override this? – przemo_li Jan 13 '17 at 21:06
  • I think `main-is` serves only to point at the right `Main` module when there are several. – sjakobi Jan 13 '17 at 21:09
  • The project worked for me when I did your created/renamed/adjusted.... Then `stack exec xyz-exe` works for me, printing "somefunc". What command are you running when you get the error? – ja. Jan 13 '17 at 21:42
  • stack build - look at accepted answer. I mistaken meaning of `main-is`, and thought it will make ghc look into different **module**, while in truth it only tells ghc to look for module `Main` inside different file then `Main.hs`. – przemo_li Jan 13 '17 at 21:50

1 Answers1

3

Is it possible you changed module Main where to module LogAnalysis where? If you did, you would get exactly this error.

Main-is just says check for the Main module inside this file, but it must still be the Main module, not the LogAnalysis module. This makes it clear that the main function in this file should be run, rather than some main functions that might happen to exist in some other modules.

David McHealy
  • 2,471
  • 18
  • 34
  • 2
    You [don't need to rename the module](https://stackoverflow.com/a/46895256). You just need to tell GHC the name of your main module. You can do this in your cabal file with: `ghc-options: -main-is LogAnalysis` – jp.rider63 Jan 28 '20 at 15:30