Question

I am trying to run a very simple "Hello World" project with cabal.

This is the folder (ubuntu) where I have saved my project

mtt@mttPC:~/Documents/Haskell/test1$ ls
dist          Greetings.o  Setup.hs  test1.cabal

Main.hs contains:

module Greetings where

main :: IO ()
main = print "hello"

Hello world actually works:

mtt@mttPC:~/Documents/Haskell/test1$ runhaskell Main.hs configure --ghc
"hello"

The test1.cabal file has been generated with cabal init:

-- Initial test1.cabal generated by cabal init.  For further documentation,
--  see http://haskell.org/cabal/users-guide/

name:                test1
version:             0.1.0.0
-- synopsis:            
-- description:         
-- license:             
license-file:        LICENSE
author:              mtt
maintainer:           
-- copyright:           
-- category:            
build-type:          Simple
cabal-version:       >=1.8

executable test1
  -- main-is: Main.hs     
  -- other-modules:     
  build-depends:       base ==4.6.*

I don't understand why:

mtt@mttPC:~/Documents/Haskell/test1$ cabal configure
Resolving dependencies...
Configuring test1-0.1.0.0...

Error: No 'Main-Is' field found for executable test1
Was it helpful?

Solution

You forgot to uncomment the file that tells GHC what module to build as the main entry point

...
executable test1
  main-is: src/Main.hs -- Or whatever is appropriate
  build-depends: base==4.6.*
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top