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

Cabal未编译库中全部模块问题求助

问题:Cabal仅编译库中一个模块,导致可执行文件找不到AST模块

相关文件与操作流程

库文件 gsdl.cabal

cabal-version:  3.6
name:           gsdl
version:        0.0
synopsis:       Global Script source manipulation libraries
homepage:       https://globalscript.org/
author:         Jonathan Cast
copyright:      © Jonathan Cast
maintainer:     Jonathan Cast <jonathanccast@fastmail.fm>
license-file:   PSL
build-type:     Simple
stability:      alpha
extra-source-files: README, COPYRIGHT

library
    build-depends: base
    exposed-modules: GSDL.Core.AST, GSDL.Core.ReadFile
    hs-source-dirs: hslib

可执行文件 gsac.cabal

cabal-version:  3.6
name:           hsgsac
version:        0.0
synopsis:       A compilation pass for converting Global Script Core code to String Code
author:         Jonathan Cast
copyright:      © Jonathan Cast
maintainer:     Jonathan Cast <jonathanccast@fastmail.fm>
license-file:   PSL
build-type:     Simple
stability:      alpha

executable gsac
    main-is: gsac.hs
    build-depends: base, gsdl

执行的命令及输出

  1. 在库源码目录执行:
cabal sdist -o /home/jcast/globalscript/haskell-packages

输出:

Wrote tarball sdist to
/home/jcast/globalscript/haskell-packages/gsdl-0.0.tar.gz
  1. 在可执行文件源码目录执行:
cabal build --config-file=/home/jcast/globalscript/etc/cabal

输出:

Build profile: -w ghc-9.0.2 -O1
In order, the following will be built (use -v for more details):
 - gsdl-0.0 (lib) (requires build)
 - hsgsac-0.0 (exe:gsac) (dependency rebuilt)
Configuring library for gsdl-0.0..
Preprocessing library for gsdl-0.0..
Building library for gsdl-0.0..
[1 of 1] Compiling GSDL.Core.ReadFile ( hslib/GSDL/Core/ReadFile.hs, dist/build/GSDL/Core/ReadFile.o, dist/build/GSDL/Core/ReadFile.dyn_o )
Installing library in /home/jcast/.cabal/store/ghc-9.0.2/incoming/new- 2347417/home/jcast/.cabal/store/ghc-9.0.2/gsdl-0.0-1a02d7c4962673481d14d20699037d04906a028286217d00fe9bce8aa1e51dcf/lib
Preprocessing executable 'gsac' for hsgsac-0.0..
Building executable 'gsac' for hsgsac-0.0..
[1 of 1] Compiling Main             ( gsac.hs, /home/jcast/src/hsgsac/dist-newstyle/build/x86_64-linux/ghc-9.0.2/hsgsac-0.0/x/gsac/build/gsac/gsac-tmp/Main.o )

gsac.hs:3:1: error:
    Could not find module ‘GSDL.Core.AST’
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
3 | import GSDL.Core.AST (cgsFileCode)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Cabal配置文件 /home/jcast/globalscript/etc/cabal

repository hackage.haskell.org
    url: http://hackage.haskell.org/

repository globalscript
    url: file+noindex:///home/jcast/globalscript/haskell-packages

库模块源码

ReadFile.hs

module GSDL.Core.ReadFile (readCoreFile) where

readCoreFile = error "readCoreFile next"

doSomethingElse = error "doSomethingElse next"

AST.hs

module GSDL.Core.AST (readCoreFile) where

readCoreFile = error "readCoreFile next"

doSomething = error "doSomething next"

问题原因分析

核心问题是生成的sdist包gsdl-0.0.tar.gz中缺少GSDL.Core.AST对应的源文件hslib/GSDL/Core/AST.hs,导致Cabal构建库时仅编译了存在的GSDL.Core.ReadFile模块,最终可执行文件编译时找不到GSDL.Core.AST模块。

可能的具体诱因:

  • AST.hs的文件路径或文件名与模块名不匹配(比如大小写错误、路径层级不对),导致Cabal生成sdist时未检测到该文件
  • 执行cabal sdist时,AST.hs尚未创建或不在指定的hs-source-dirs(hslib)目录下
  • Cabal版本兼容性问题,导致未正确收集exposed-modules中声明的所有模块文件

解决建议

  1. 验证文件路径:确认AST.hs位于hslib/GSDL/Core/目录下,文件名与模块名一致(区分大小写)
  2. 检查sdist包内容:解压gsdl-0.0.tar.gz,确认其中包含hslib/GSDL/Core/AST.hs
  3. 重新生成sdist:在库源码目录执行cabal sdist --list,查看待打包文件列表,确认AST.hs在其中,再重新生成并发布到本地仓库
  4. 显式声明文件(可选):在gsdl.cabal的extra-source-files中添加hslib/GSDL/Core/AST.hs,强制Cabal将其包含进sdist包

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 06:48:14