Cabal 不构建可执行文件
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
消息里都有:
你需要一个 source 文件来定义 Main 模块
module Main where ...
并导出一个main
函数:
main :: IO ()
main = ...
你的 .cabal 文件中的 main-is
字段应该指向这个。
如果你拥有所有这些,你应该能够将它编译成可执行文件。
这是一个很好的介绍:How to write a Haskell programm
更新
事实证明模块被命名为 Core.Main
- 确保你也有一个 module Main
- 你总是可以添加一个顶层 main.hs
并仅重新导出 main
也来自 Core.Main
出于某种原因,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
消息里都有:
你需要一个 source 文件来定义 Main 模块
module Main where ...
并导出一个main
函数:
main :: IO ()
main = ...
你的 .cabal 文件中的 main-is
字段应该指向这个。
如果你拥有所有这些,你应该能够将它编译成可执行文件。
这是一个很好的介绍:How to write a Haskell programm
更新
事实证明模块被命名为 Core.Main
- 确保你也有一个 module Main
- 你总是可以添加一个顶层 main.hs
并仅重新导出 main
也来自 Core.Main