[英]Cabal Doesn't Build Executable
由于某种原因,cabal并未为我的程序创建可执行文件。 运行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
当然,在dist/build/server/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
我的目录结构(包括来自cabal build
dist
):
.
├── 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
main
定义:
main :: IO ()
main = do
db <- openLocalStateFrom "~/.acid-state" (UserDatabase Map.empty)
putStrLn $ "http://localhost:8080/"
run 8080 $ logStdout $ staticPolicy (noDots >-> addBase "../client/") $ app db
消息中的全部内容:
您需要定义主模块的源文件
module Main where ...
并导出main
功能:
main :: IO ()
main = ...
并且.cabal文件中的main-is
字段应指向此字段。
如果拥有所有这些,您应该可以将其编译为可执行文件。
这是一个不错的介绍: 如何编写Haskell程序
事实证明,该模块被命名为Core.Main
确保您也拥有一个module Main
-您始终可以添加顶级main.hs
并从Core.Main
仅Core.Main
main
Core.Main
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.