我想将我的项目组织到不同的库中,因为最终我可能会将一些拆分到外部存储库中。
在一个.cabal文件中,我可以有多个库(我相信一个未命名,多个命名):
library
import: servant-deps
exposed-modules:
App
other-modules:
Paths_cow_streamer
hs-source-dirs:
src
build-depends:
servant-server >= 0.15
library sxapi
import: servant-deps
exposed-modules:
SxClient
other-modules:
Paths_cow_streamer
hs-source-dirs:
sxapi
build-depends:
http-client
Run Code Online (Sandbox Code Playgroud)
最初我在我的 hpack 中尝试这样package.yaml:
library:
bar:
source-dirs:
- src
dependencies:
- servant-server >= 0.14
- wai
- warp
foo:
source-dirs:
- sxapi
dependencies:
- servant-server >= 0.14
- wai
- warp
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,似乎没有一个条目被正确解释,因为例如 source-dirs 不存在于生成的 cabal 文件中。
我也试过这个,但不出所料,库定义之一被覆盖:
library:
source-dirs:
- src
dependencies:
- servant-server >= 0.14
- wai
- warp …Run Code Online (Sandbox Code Playgroud) 我使用默认stack new设置来设置一个项目,该项目将一个服务器和一个客户端作为单独的可执行文件。我package.yaml以正确的方式更改了文件(截至 2020 年 4 月 21 日“没有用户指南”),并向我的app目录中添加了一个名为Client.hs.
我收到一条错误消息:“为非法列在‘其他模块’中的主模块‘Main’启用变通方法!”
我如何让堆栈构建客户端和服务器?
当我跑stack build我得到:
[... clip ...]
Building executable 'ObjectServer' for ObjectServer-0.1.0.1..
[4 of 4] Compiling Client
Linking .stack-work\dist\29cc6475\build\ObjectServer\ObjectServer.exe ...
Warning: Enabling workaround for Main module 'Main' listed in 'other-modules'
illegally!
Preprocessing executable 'Client' for ObjectServer-0.1.0.1..
Building executable 'Client' for ObjectServer-0.1.0.1..
[3 of 3] Compiling Client
<no location info>: error:
output was redirected with -o, but no output will be …Run Code Online (Sandbox Code Playgroud)