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: somebody@gmail.com
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
it's all there in the message:
you need a source file defining the Main module
module Main where ...
and exporting a main
function:
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.