出于某种原因,阴谋集团没有为我的程序创建可执行文件。当我运行cabal build时,我得到了以下输出:
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.随后的cabal run给出了以下错误:
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当然,在server中没有dist/build/server/server二进制文件。但是,临时文件在dist/build/server/server-temp/中。
我的.cabal文件:
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我的目录结构(包括来自dist的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.hsmain定义:
main :: IO ()
main = do
db <- openLocalStateFrom "~/.acid-state" (UserDatabase Map.empty)
putStrLn $ "http://localhost:8080/"
run 8080 $ logStdout $ staticPolicy (noDots >-> addBase "../client/") $ app db发布于 2015-04-21 17:05:04
所有这些都在信息里:
您需要一个源文件来定义主模块
module Main where ...并导出一个main函数:
main :: IO ()
main = ...而您的main-is文件中的.cabal字段应该指向以下内容。
如果您拥有所有这些,您应该能够将其编译成一个可执行文件。
这里有一个很好的介绍:如何编写Haskell程序
更新
结果是,模块名为Core.Main --确保您也有一个module Main --您总是可以添加顶级main.hs并从Core.Main重新导出main。
https://stackoverflow.com/questions/29778382
复制相似问题