2

For some reason, cabal isn't creating an executable for my program. When I run cabal build, I get this output:

Building server-0.1.0.0...
Preprocessing executable 'server' for server-0.1.0.0...
Warning: output was redirected with -o, but no output will be generated
because there is no Main module.

A subsequent cabal run gives me this error:

Preprocessing executable 'server' for server-0.1.0.0...
Warning: output was redirected with -o, but no output will be generated
because there is no Main module.
cabal: dist/build/server/server: does not exist

Sure enough, there is no server binary in dist/build/server/server. The temp files are, however, in dist/build/server/server-temp/.

My .cabal file:

name:                server
version:             0.1.0.0
synopsis:            An example haskell web service.
license:             Apache-2.0
license-file:        LICENSE
author:              Some Body
maintainer:          [email protected]
category:            Web
build-type:          Simple
cabal-version:       >=1.10
executable server
  main-is:             Core/Main.hs
  build-depends:       base,
                       containers,
                       bytestring,
                       bytestring-conversion,
                       aeson,
                       http-types,
                       acid-state,
                       mtl,
                       safecopy,
                       warp,
                       wai,
                       wai-extra,
                       wai-middleware-static
  hs-source-dirs:      src
  default-language:    Haskell2010

My directory structure (including dist from cabal build):

.
├── cabal.sandbox.config
├── dist
│   ├── build
│   │   ├── autogen
│   │   │   ├── cabal_macros.h
│   │   │   └── Paths_server.hs
│   │   └── server
│   │       └── server-tmp
│   │           ├── Core
│   │           │   ├── Main.dyn_hi
│   │           │   ├── Main.dyn_o
│   │           │   ├── Main.hi
│   │           │   └── Main.o
│   │           ├── Model
│   │           │   ├── DB.dyn_hi
│   │           │   ├── DB.dyn_o
│   │           │   ├── DB.hi
│   │           │   └── DB.o
│   │           └── Util
│   │               ├── HTTP.dyn_hi
│   │               ├── HTTP.dyn_o
│   │               ├── HTTP.hi
│   │               └── HTTP.o
│   ├── package.conf.inplace
│   │   └── package.cache
│   └── setup-config
├── LICENSE
├── server.cabal
├── Setup.hs
└── src
    ├── Core
    │   └── Main.hs
    ├── Model
    │   └── DB.hs
    ├── Service
    └── Util
        └── HTTP.hs

The main definition:

main :: IO ()
main = do
  db <- openLocalStateFrom "~/.acid-state" (UserDatabase Map.empty)
  putStrLn $ "http://localhost:8080/"
  run 8080 $ logStdout $ staticPolicy (noDots >-> addBase "../client/") $ app db
4
  • Post your project's cabal config file ? Commented Apr 21, 2015 at 17:01
  • I've added the config file & dir structure Commented Apr 21, 2015 at 18:27
  • 1
    Not sure but if you use Core/Main.hs is it possible that your module is indeed Core.Main if so you still need to make a top-level Main.hs with module Main without anything else! Commented Apr 21, 2015 at 19:21
  • You got it. The issue was that my main module was Core.Main and not simply Main. I moved src/Core/Main.hs to src/Main.hs and changed my main-is: entry to Main.hs Commented Apr 21, 2015 at 19:29

1 Answer 1

2

it's all there in the message:

you need a source file defining the Main module

module Main where ...

and exporting a mainfunction:

main :: IO ()
main = ...

and your main-is field in your .cabal file should point to this.

If you have all this you should be able to compile it into an executable.

Here is a nice intro: How to write a Haskell programm

update

as it turn out the module was named Core.Main - make sure you have one module Main too - you can always add a top level main.hs and reexport just the main from Core.Main too

Sign up to request clarification or add additional context in comments.

4 Comments

It does! That's what's weird about it. I'll post my .cabal when I'm back in ~1hr
Oh - sorry this does not help - I'll let my answer stick for now if you don't mind. Can you post something about your file structure and your the beginning of the file containing your Main module too please?
No worries. I have added my directory structure and my .cabal file to the question. I'll also add the main definition.
your main definition only gives the main function, but you don't show the module name. Does your source file start with module Main where as Carsten said?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.