无法在 macOS Mac M1 上安装 OCaml

Unable to install OCaml on macOS Mac M1

我在 6 个月前安装了 merlin,以便能够编译 Ocaml,我没有遇到任何问题。我最近已升级以更新所有内容,但无法使软件包正常工作。

当我尝试重新安装它时,我收到此错误消息 (opam install -y merlin):

[coq-released] synchronised from https://coq.inria.fr/opam/released
[default] no changes from https://opam.ocaml.org
The following actions will be performed:
  ∗ install ocaml-base-compiler 4.12.0  [required by ocaml]
  ∗ install ocaml-config        2       [required by ocaml]
  ∗ install ocaml               4.12.0  [required by merlin]
  ∗ install ocamlfind           1.9.3   [required by dot-merlin-reader]
  ∗ install dune                2.9.3   [required by merlin]
  ∗ install result              1.5     [required by merlin]
  ∗ install easy-format         1.3.2   [required by yojson]
  ∗ install csexp               1.5.1   [required by merlin]
  ∗ install cppo                1.6.8   [required by yojson]
  ∗ install biniou              1.2.1   [required by yojson]
  ∗ install yojson              1.7.0   [required by merlin]
  ∗ install dot-merlin-reader   4.1     [required by merlin]
  ∗ install merlin              4.4-412
===== ∗ 13 =====

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>   
⬇ retrieved biniou.1.2.1  (cached)
⬇ retrieved csexp.1.5.1  (cached)
⬇ retrieved dot-merlin-reader.4.1  (cached)
⬇ retrieved cppo.1.6.8  (cached)
⬇ retrieved easy-format.1.3.2  (cached)
⬇ retrieved dune.2.9.3  (cached)
⬇ retrieved ocaml-base-compiler.4.12.0  (cached)
⬇ retrieved result.1.5  (cached)
⬇ retrieved ocamlfind.1.9.3  (cached)
⬇ retrieved yojson.1.7.0  (cached)
⬇ retrieved merlin.4.4-412  (cached)
[ERROR] The installation of ocaml-base-compiler failed at "make install".

#=== ERROR while installing ocaml-base-compiler.4.12.0 ========================#
# context     2.1.2 | macos/arm64 |  | https://opam.ocaml.org#71d8d30e
# path        ~/.opam/4.12.0/.opam-switch/build/ocaml-base-compiler.4.12.0
# command     ~/.opam/opam-init/hooks/sandbox.sh install make install
# exit-code   2
# env-file    ~/.opam/log/ocaml-base-compiler-11755-86d59b.env
# output-file ~/.opam/log/ocaml-base-compiler-11755-86d59b.out
### output ###
# if test -f ocamlnat ; then \
# [...]
#        "/Users/theosouchon/.opam/4.12.0/lib/ocaml"; \
#     /usr/bin/install -c -m 644 \
#        toplevel/opttopstart.cmx toplevel/opttopstart.o \
#        "/Users/theosouchon/.opam/4.12.0/lib/ocaml/compiler-libs"; \
#   fi
# cd "/Users/theosouchon/.opam/4.12.0/lib/ocaml/compiler-libs" && \
#      ranlib ocamlcommon.a ocamlbytecomp.a ocamloptcomp.a
# ranlib: error: exactly one archive should be specified
# make[2]: *** [installoptopt] Error 1
# make[1]: *** [installopt] Error 2
# make: *** [install] Error 2

如果你有解决这个问题的想法我很感兴趣

非常感谢, 西奥苏雄

您遇到的问题与merlin本身无关。问题是您无法使用您机器上默认使用的 llvm 工具链构建编译器。

GNU 版本的 ranlib 工具能够接受多个存档参数,这与 llvm 版本的 ranlib 不同,后者在多个存档上失败。

一般的答案是您应该安装并 select GNU 工具链以构建 OCaml。我会从 运行ning which ranlib 开始我的调查,以了解为什么你在 PATH 中有损坏的 ranlib。也有可能您使用 brew 安装 llvm 工具链,然后使用 brew unlink 撤消此操作。最后,您希望 ranlibranlib --version 打印 GNU ranlib 的路径中,而不是 LLVM.

此外,在 macOS 中,有一个名为 xcode-select 的工具可以让您安装和 select 工具链。我没有可用的最新版本的 macOS,所以我不能确定,但​​你可以尝试 运行 xcode-select --install 安装工具链并使用 xcode-select --switch 到 select一个合适的。

综上所述,OCaml and opam 问题跟踪器比 SO 更适合解决此类问题。