尝试通过 cabal 安装 hashable 时出现“致命错误:找不到‘ffi.h’文件”

Ane*_*pic 5 haskell

我在 Macos 上(M1 MacBook Air)

我通过 ghcup 安装了 Haskell 工具链,目前已ghc设置为 9.6.1

我运行了cabal build该项目,但安装依赖项之一失败:

Building library for hashable-1.4.2.0..
[1 of 7] Compiling Data.Hashable.Imports ( src/Data/Hashable/Imports.hs, dist/build/Data/Hashable/Imports.o, dist/build/Data/Hashable/Imports.dyn_o )
[2 of 7] Compiling Data.Hashable.LowLevel ( src/Data/Hashable/LowLevel.hs, dist/build/Data/Hashable/LowLevel.o, dist/build/Data/Hashable/LowLevel.dyn_o )

/var/folders/w1/_vgkxyln4c7bk8kr29s1y1k00000gn/T/ghc83995_0/ghc_10.c:4:10: error:
     fatal error: 'ffi.h' file not found
  |
4 | #include <ffi.h>
  |          ^
#include <ffi.h>
         ^~~~~~~
1 error generated.

<no location info>: error:
    `gcc' failed in phase `C Compiler'. (Exit code: 1)
Error: cabal: Failed to build hashable-1.4.2.0 (which is required by
Run Code Online (Sandbox Code Playgroud)

Ane*_*pic 7

在开发人员的帮助下进行诊断和修复ghcup
https ://github.com/haskell/ghcup-hs/issues/814

问题是我在最近的 macOS 或 XCode 软件更新后没有重新安装 XCode 命令行工具。

通过安装命令行工具可以解决此问题:

xcode-select --install
Run Code Online (Sandbox Code Playgroud)

这确保了预期的符号链接位于/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

cabal build然后就能够成功