You need to enable JavaScript to run this app. GitHub Actions Ubuntu Runner上cabal install执行失败求助
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions Ubuntu Runner上cabal install执行失败求助

Cabal Install 目标匹配歧义报错的解决方法

问题场景

使用GitHub CI的ubuntu-latest runner,搭配GHC 9.6.6和Cabal 3.12.1.0构建Scotty Web服务,cabal build执行成功,但执行以下install命令时失败:

cabal install exe:some_exe --installdir /root --overwrite-policy=always --install-methody=copy

报错信息:

Internal error in target matching: could not make and unambiguous fully qualified target selector for ‘exe:some_exe’.
We made the target ‘exe:some_exe’ (unknown-component) that was expected to be unambiguous but matches the following targets:
‘exe:some_exe’, matching:
exe:some_exe (unknown-component)
:pkg:exe:lib:exe:file:some_exe (unknown-file)
Note: Cabal expects to be able to make a single fully qualified name for a target or provide a more specific error. Our failure to do so is a bug in cabal. Tracking issue:
Tracking issue: internal error in target matching · Issue #8684 · haskell/cabal · GitHub
Hint: this may be caused by trying to build a package that exists in the project directory but is missing from the ‘packages’ stanza in your cabal project file.

解决方法

1. 修正命令拼写错误

命令中的--install-methody=copy存在拼写错误,正确参数应为--install-method=copy,拼写错误可能干扰命令解析,导致目标匹配异常。修正后的命令:

cabal install exe:some_exe --installdir /root --overwrite-policy=always --install-method=copy

2. 明确指定包名消除目标歧义

仅用exe:some_exe可能因同名文件/组件导致匹配歧义,需加上包名限定目标,格式为[包名]:exe:[可执行文件名]。假设你的包名为my-scotty-service,命令改为:

cabal install my-scotty-service:exe:some_exe --installdir /root --overwrite-policy=always --install-method=copy

若不确定包名,可执行cabal list查看项目内的包名称。

3. 检查并修正cabal.project配置

根据报错提示,确认cabal.project文件的packages stanza包含当前要构建的包:

  • 若包在当前目录,确保配置为:
    packages: .
    
  • 若包在子目录,指定具体路径,比如:
    packages: ./my-scotty-service
    

修改后重新执行cabal build再尝试install。

4. 清理Cabal缓存与构建目录

旧的构建缓存或元数据可能导致目标匹配异常,执行以下命令清理后重试:

cabal clean
rm -rf dist-newstyle

之后重新运行cabal build和install命令。

5. 跳过install,直接复制构建好的二进制文件

如果上述方法仍无法解决,可直接从Cabal构建输出目录复制二进制文件,绕开install的目标匹配问题:

# 获取可执行文件路径并复制到目标目录
cp $(cabal list-bin exe:some_exe) /root/

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 13:40:11