macosocamlapple-m1merlindune

Unable to install OCaml on macOS Mac M1


I had installed merlin 6 months ago to be able to compile Ocaml and I had no problems. I have recently upgraded to update everything but it was impossible to make the package work.

When I try to reinstall it I get this error message (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

If you ever have an idea to solve this problem I'm interested

Thank you very much, Theo Souchon


Solution

  • The issue that you have has nothing to do with merlin per se. The problem is that you can't build the compiler using the llvm toolchain, which is used by default on your machine.

    The GNU version of the ranlib tool is able to take several archive arguments, unlike the llvm version of ranlib that fails on more than one archive.

    The general answer is that you should install and select the GNU toolchain in order to build OCaml. I would start my investigation with running which ranlib to understand why you have the broken ranlib in the PATH. It could also be possible that you used brew to install the llvm toolchain, then use brew unlink to undo this. In the end, you want ranlib in your path that for ranlib --version prints GNU ranlib, not LLVM.

    Also, in macOS, there's the tool called xcode-select that lets you install and select the toolchains. I don't have the latest version of macOS available, so I can't be sure, but you can try to run xcode-select --install to install the toolchain and use xcode-select --switch to select an appropriate one.

    With all that said, the OCaml and opam issue trackers are much better places to resolve such problems than SO.