使用Cabal安装Haskell性能分析库遇到问题求助
问题背景
给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 -vin 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。
解决方案
清理项目构建缓存
执行命令彻底清除旧构建产物,避免缓存干扰:cabal clean针对项目环境安装profiling依赖
不要用全局--lib安装,而是让Cabal针对当前项目处理依赖:- 直接带profiling选项构建项目,Cabal会自动安装所需依赖的profiling版本:
cabal build --enable-profiling - 或先单独安装所有依赖的profiling版本:
cabal install --enable-profiling --dependencies-only
- 直接带profiling选项构建项目,Cabal会自动安装所需依赖的profiling版本:
强制匹配版本安装
确认项目依赖的unordered-containers版本与安装的profiling版本一致,可指定版本安装:cabal install unordered-containers-0.2.19.1 --enable-profiling --dependencies-only验证Cabal环境状态
执行以下命令查看当前环境下的unordered-containers包状态,确认存在profiling版本:cabal list unordered-containers如果没有,先更新包索引:
cabal update再重新执行带
--enable-profiling的构建命令。
关键说明
全局安装的profiling库可能和项目使用的Cabal快照/本地依赖环境不匹配,因此必须针对项目本身触发依赖的profiling版本安装,才能让GHC找到对应的库文件。
内容的提问来源于stack exchange,提问作者simmysilver

