编译Pandoc源码遇Stack报错:ghc-options字段解析失败($locals无效)
Ah, I've run into this exact issue before when building Pandoc with an older Stack version! Let's break down what's happening and how to fix it:
问题根源
The error you're seeing is almost certainly due to using an outdated version of Stack. The $locals syntax is a relatively recent addition to Stack—it's a special variable that refers to all local packages in your project. Older Stack versions don't recognize this variable, so they mistakenly try to parse $locals as a literal package name, which throws that "invalid package name" error.
解决方案步骤
升级Stack到最新版本
这是最关键的修复步骤。在终端运行以下命令更新Stack:stack upgrade如果是Windows系统,可能需要以管理员权限打开终端执行该命令。
清理完整构建缓存(可选但推荐)
即使升级了Stack,旧的构建缓存有时仍会导致遗留问题。执行以下命令清空完整缓存:stack clean --full重新构建Pandoc
回到Pandoc源码目录,再次运行构建命令:stack build
额外检查(若升级后仍有问题)
如果升级后依然报错,可以检查项目的stack.yaml文件,确认使用$locals的ghc-options部分格式是否正确——正确的写法大致如下:
ghc-options: $locals: -Wall -Werror
不过如果你严格按照官方构建步骤操作,这大概率不是问题所在,版本不匹配才是最常见的诱因。
内容的提问来源于stack exchange,提问作者brandizzi

