在 macOS Sierra 上安装 ocamlfind.1.8.0

Installing ocamlfind.1.8.0 on macOS Sierra

我正在跟随 dev.realworldocaml.org 学习 OCaml。我在无法访问 ocamlfind 库的地方进行安装。

我的默认 ocaml 是通过自制软件安装的 4.07.0:

PrisBook:~ prisc_000$ brew list ocaml

/usr/local/Cellar/ocaml/4.07.0_1/bin/ocaml

Opam 是 opam V2:

PrisBook:~ prisc_000$ opam --version 2.0.0

当我尝试安装 opam install core utop 时,出现以下错误。

> PrisBook:~ prisc_000$ opam switch
#  switch   compiler             description
→  default  ocaml-system.4.07.0  default
PrisBook:~ prisc_000$ opam install core utop
The following actions will be performed:
  ∗ install jane-street-headers     v0.11.0
          [required by core_kernel]
  ∗ install ocamlfind               1.8.0
          [required by utop]
  ∗ install seq                     base
          [required by re]
  ∗ install camomile                1.0.1
          [required by utop]
  ∗ install spawn                   v0.12.0
          [required by core]
  ∗ install ocaml-compiler-libs     v0.11.0
          [required by ppxlib]
  ∗ install sexplib0                v0.11.0
          [required by base]
  ∗ install ppx_derivers            1.0
          [required by ppxlib]
  ∗ install topkg                   0.9.1
          [required by react]
  ∗ install octavius                1.2.0
          [required by ppx_js_style]
  ∗ install ocaml-migrate-parsetree 1.0.11
          [required by core]
  ∗ install num                     1.1
          [required by sexplib]
  ∗ install base-bytes              base
          [required by cppo]
  ∗ install re                      1.8.0
          [required by ppx_expect]
  ∗ install parsexp                 v0.11.0
          [required by sexplib]
  ∗ install base                    v0.11.1
          [required by core]
  ∗ install react                   1.2.1
          [required by utop]
  ∗ install cppo                    1.6.4
          [required by utop]
  ∗ install sexplib                 v0.11.0
          [required by core]
  ∗ install typerep                 v0.11.0
          [required by core_kernel]
  ∗ install stdio                   v0.11.0
          [required by core]
  ∗ install zed                     1.6
          [required by lambda-term]
  ∗ install lwt                     4.1.0
          [required by utop]
          For the PPX, please install package lwt_ppx
  ∗ install ppxlib                  0.3.0
          [required by core]
  ∗ install configurator            v0.11.0
          [required by core]
  ∗ install lwt_react               1.1.1
          [required by utop]
  ∗ install lwt_log                 1.1.0
          [required by lambda-term]
  ∗ install variantslib             v0.11.0
          [required by core_kernel]
  ∗ install ppx_typerep_conv        v0.11.1
          [required by ppx_jane]
  ∗ install ppx_sexp_conv           v0.11.2
          [required by core_kernel]
  ∗ install ppx_pipebang            v0.11.0
          [required by ppx_jane]
  ∗ install ppx_optional            v0.11.0
          [required by ppx_jane]
  ∗ install ppx_optcomp             v0.11.0
          [required by ppx_jane]
  ∗ install ppx_let                 v0.11.0
          [required by ppx_jane]
  ∗ install ppx_js_style            v0.11.0
          [required by ppx_base]
  ∗ install ppx_inline_test         v0.11.0
          [required by core_kernel]
  ∗ install ppx_here                v0.11.0
          [required by ppx_assert, ppx_jane]
  ∗ install ppx_enumerate           v0.11.1
          [required by ppx_base]
  ∗ install ppx_compare             v0.11.1
          [required by ppx_assert, bin_prot, ppx_base]
  ∗ install fieldslib               v0.11.0
          [required by core_kernel]
  ∗ install lambda-term             1.13
          [required by utop]
  ∗ install ppx_variants_conv       v0.11.1
          [required by bin_prot, ppx_jane]
  ∗ install ppx_custom_printf       v0.11.0
          [required by bin_prot, ppx_jane]
  ∗ install ppx_bench               v0.11.0
          [required by ppx_jane]
  ∗ install ppx_sexp_value          v0.11.0
          [required by ppx_jane]
  ∗ install ppx_sexp_message        v0.11.0
          [required by core_kernel]
  ∗ install ppx_fail                v0.11.0
          [required by ppx_jane]
  ∗ install ppx_hash                v0.11.1
          [required by core_kernel]
  ∗ install ppx_assert              v0.11.0
          [required by core]
  ∗ install ppx_fields_conv         v0.11.0
          [required by bin_prot, ppx_jane]
  ∗ install utop                    2.2.0
  ∗ install ppx_base                v0.11.0
          [required by core_kernel]
  ∗ install ppx_expect              v0.11.0
          [required by ppx_jane]
  ∗ install bin_prot                v0.11.0
          [required by core_kernel]
  ∗ install ppx_bin_prot            v0.11.1
          [required by ppx_jane]
  ∗ install ppx_jane                v0.11.0
          [required by core]
  ∗ install splittable_random       v0.11.0
          [required by core_kernel]
  ∗ install core_kernel             v0.11.1
          [required by core]
  ∗ install core                    v0.11.2
===== ∗ 59 =====
Do you want to continue? [Y/n] y

<><> Gathering sources ><><><><><><><><><><><><><><><><>  
[base.v0.11.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[bin_prot.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[configurator.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[core_kernel.v0.11.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[core.v0.11.2] downloaded from cache at https://opam.ocaml.org/2.0/cache
[camomile.1.0.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[cppo.1.6.4] downloaded from cache at https://opam.ocaml.org/2.0/cache
[fieldslib.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[jane-street-headers.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[lambda-term.1.13] downloaded from cache at https://opam.ocaml.org/2.0/cache
[lwt_log.1.1.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[lwt.4.1.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ocaml-compiler-libs.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[num.1.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ocamlfind.1.8.0] found in cache
[lwt_react.1.1.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ocaml-migrate-parsetree.1.0.11] downloaded from cache at https://opam.ocaml.org/2.0/cache
[octavius.1.2.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[parsexp.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_assert.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_base.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_bench.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_compare.v0.11.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_bin_prot.v0.11.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_custom_printf.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_derivers.1.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_enumerate.v0.11.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_fail.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_expect.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_fields_conv.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_hash.v0.11.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_here.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_inline_test.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_jane.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_js_style.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_let.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_optcomp.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_optional.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_pipebang.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_sexp_message.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_sexp_conv.v0.11.2] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_sexp_value.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_typerep_conv.v0.11.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppx_variants_conv.v0.11.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[ppxlib.0.3.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[react.1.2.1] downloaded from cache at https://opam.ocaml.org/2.0/cache
[re.1.8.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[sexplib0.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[spawn.v0.12.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[sexplib.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[topkg.0.9.1] found in cache
[splittable_random.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[stdio.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[typerep.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[variantslib.v0.11.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[utop.2.2.0] downloaded from cache at https://opam.ocaml.org/2.0/cache
[zed.1.6] downloaded from cache at https://opam.ocaml.org/2.0/cache

<><> Processing actions <><><><><><><><><><><><><><><><>  
∗ installed jane-street-headers.v0.11.0
∗ installed ocaml-compiler-libs.v0.11.0
∗ installed ppx_derivers.1.0
∗ installed seq.base
[ERROR] The compilation of ocamlfind failed at
        "/Users/prisc_000/.opam/opam-init/hooks/sandbox.sh
        build make all".
∗ installed sexplib0.v0.11.0
∗ installed parsexp.v0.11.0
∗ installed re.1.8.0
∗ installed spawn.v0.12.0
∗ installed camomile.1.0.1
∗ installed base.v0.11.1
∗ installed stdio.v0.11.0
∗ installed typerep.v0.11.0
∗ installed configurator.v0.11.0

#=== ERROR while compiling ocamlfind.1.8.0 ================#
# context     2.0.0 | macos/x86_64 | ocaml-system.4.07.0 | https://opam.ocaml.org/2.0#0a261aa5
# path        ~/.opam/default/.opam-switch/build/ocamlfind.1.8.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build make all
# exit-code   2
# env-file    ~/.opam/log/ocamlfind-1333-da938f.env
# output-file ~/.opam/log/ocamlfind-1333-da938f.out
### output ###
# [...]
# USE_CYGPATH="0"; \
#   export USE_CYGPATH; \
#   cat topfind_rd1.p | \
#            ../../tools/patch '@SITELIB@' '/Users/prisc_000/.opam/default/lib' \
#               >topfind
# ocamlc -I +compiler-libs -opaque -c num_top_printers.mli
# File "num_top_printers.mli", line 1:
# Error: /usr/local/lib/ocaml/nat.cmi
# is not a compiled interface for this version of OCaml.
# It seems to be for an older version of OCaml.
# make[1]: *** [num_top_printers.cmi] Error 2
# make: *** [all] Error 2



<><> Error report <><><><><><><><><><><><><><><><><><><>  
┌─ The following actions failed
│ λ build ocamlfind 1.8.0
└─
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install base                v0.11.1
│ ∗ install camomile            1.0.1
│ ∗ install configurator        v0.11.0
│ ∗ install jane-street-headers v0.11.0
│ ∗ install ocaml-compiler-libs v0.11.0
│ ∗ install parsexp             v0.11.0
│ ∗ install ppx_derivers        1.0
│ ∗ install re                  1.8.0
│ ∗ install seq                 base
│ ∗ install sexplib0            v0.11.0
│ ∗ install spawn               v0.12.0
│ ∗ install stdio               v0.11.0
│ ∗ install typerep             v0.11.0
└─

The former state can be restored with:
    opam switch import
"/Users/prisc_000/.opam/default/.opam-switch/backup/state-20180908080830.export"

我不太确定这里发生了什么,因为我是新手。如何在 mac 上安装 ocamlfind

谢谢。

错误似乎发生在 opam 沙箱脚本周围 运行

解决方案:

在这种情况下,解决方案是进入 usr/local/bin,在那里我展示了一些以前版本的 opam 和 opam v2。我手动删除了所有 opam。然后我 运行 brew remove camlp4 ocamlbuild ocaml 这样 opam 就只会看到 ocaml 编译器的沙盒版本。我删除了 ~/.opam 目录,然后通过 git 重新安装了它 wget https://raw.github.com/ocaml/opam/master/shell/install.sh 因为 opam v2 在安装 opam 1.2 的自制程序上尚不可用。

然后我 运行 opam install core utop ocamlbuild 1.8.0 安装成功。

注意:此设置没有破坏我的 reasonml 项目。

我的 OCaml 版本:The OCaml toplevel, version 4.07.0
我的 opam 版本:2.0.1

我 运行 在安装 ocamlfind 1.8.0 时遇到同样的问题。这是因为我的 /usr/local/lib/ocaml/nat.cmi 文件适用于旧版本的 OCaml。我删除了 /usr/local/lib/ocaml 文件夹并通过自制软件重新安装了 OCaml。然后命令 opam install core utop 在我这边运行良好。