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

使用Cabal安装Haskell性能分析库遇到问题求助

解决Cabal项目开启性能分析时找不到unordered-containers profiling库的问题

问题背景

给Cabal项目的ghc-options添加-prof和-fprof-auto后,执行cabal build报错:

app/WordMap.hs:5:1: error:
Could not find module ‘Data.HashMap.Strict’
Perhaps you haven't installed the profiling libraries for package ‘unordered-containers-0.2.19.1’?
Use -v (or :set -v in ghci) to see a list of the files searched for.
|
5 | import qualified Data.HashMap.Strict as HashMap
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

未添加profiling选项时编译正常,已尝试全局安装带profiling的unordered-containers但无效,使用GHC 9.2.4、Cabal 3.6.2.0。

解决方案

  1. 清理项目构建缓存
    执行命令彻底清除旧构建产物,避免缓存干扰:

    cabal clean
    
  2. 针对项目环境安装profiling依赖
    不要用全局--lib安装,而是让Cabal针对当前项目处理依赖:

    • 直接带profiling选项构建项目,Cabal会自动安装所需依赖的profiling版本:
      cabal build --enable-profiling
      
    • 或先单独安装所有依赖的profiling版本:
      cabal install --enable-profiling --dependencies-only
      
  3. 强制匹配版本安装
    确认项目依赖的unordered-containers版本与安装的profiling版本一致,可指定版本安装:

    cabal install unordered-containers-0.2.19.1 --enable-profiling --dependencies-only
    
  4. 验证Cabal环境状态
    执行以下命令查看当前环境下的unordered-containers包状态,确认存在profiling版本:

    cabal list unordered-containers
    

    如果没有,先更新包索引:

    cabal update
    

    再重新执行带--enable-profiling的构建命令。

关键说明

全局安装的profiling库可能和项目使用的Cabal快照/本地依赖环境不匹配,因此必须针对项目本身触发依赖的profiling版本安装,才能让GHC找到对应的库文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 01:25:27