You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何避免因内部库依赖传递重复声明Cabal build-depends?

Haskell项目Cabal配置问题

项目初始结构

.
├── Main.hs
├── mynot.cabal
├── Notification.hs
└── Server.hs

初始mynot.cabal配置

cabal-version:   3.0
name:            mynot
version:         0.1.0.0

common common
    default-language: GHC2021
    build-depends: base

executable mynot
    import: common
    main-is: Main.hs
    build-depends: dbus
                 , async
                 , containers
                 , extra
                 , flow
    other-modules: Server
                 , Notification

library server
    import: common
    exposed-modules: Server
    build-depends: async
                 , containers
                 , dbus
                 , extra
                 , flow
    other-modules: Notification

library notification
    import: common
    exposed-modules: Notification
    build-depends: containers
                 , dbus
                 , extra

疑问:extra依赖的冗余声明问题

extra包仅被Notification.hs使用,但如果不在executable mynot和library server的build-depends里声明它,Cabal构建就会失败,我搞不懂为什么必须这么做。

尝试调整后的报错

为了优化依赖结构,我做了以下操作:

$ mkdir exe
$ mv Main.hs exe/.

然后在executable mynot的配置块中添加了hs-source-dirs: exe,但执行构建时失败,报错信息如下:

Resolving dependencies...
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
 - mynot-0.1.0.0 (exe:mynot) (configuration changed)
 - mynot-0.1.0.0 (lib:notification) (configuration changed)
 - mynot-0.1.0.0 (lib:server) (configuration changed)
Configuring executable 'mynot' for mynot-0.1.0.0..
Configuring library 'notification' for mynot-0.1.0.0..
Configuring library 'server' for mynot-0.1.0.0..
Preprocessing library 'notification' for mynot-0.1.0.0..
Building library 'notification' for mynot-0.1.0.0..
Preprocessing executable 'mynot' for mynot-0.1.0.0..
Error: cabal-3.10.2.1: can't find source for Server in exe,
/home/enrico/mynot/dist-newstyle/build/x86_64-linux/ghc-9.4.8/mynot-0.1.0.0/x/mynot/build/mynot/autogen,
/home/enrico/mynot/dist-newstyle/build/x86_64-linux/ghc-9.4.8/mynot-0.1.0.0/x/mynot/build/global-autogen

Preprocessing library 'server' for mynot-0.1.0.0..
Building library 'server' for mynot-0.1.0.0..
Error: cabal: Failed to build exe:mynot from mynot-0.1.0.0.

请问是我的项目本身存在问题,还是缺少必要的配置?

内容的提问来源于stack exchange,提问作者Enrico

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 15:07:08