我的问题与此类似,但是,在我的情况下.ocamlinit已设置。
这是我的 ocaml 版本。
\n\nmymac:Desktop myusr$ ocaml --version\nThe OCaml toplevel, version 4.08.1\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的 opam 版本。
\n\nmymac:Desktop myusr$ opam --version\n2.0.5\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的 opam 开关。
\n\nmymac:Desktop myusr$ opam switch\n# switch compiler description\n\xe2\x86\x92 4.08.1 ocaml-base-compiler.4.08.1 4.08.1\n default ocaml-base-compiler.4.08.1 default\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的.ocamlinit:
mymac:Desktop myusr$ cat ~/.ocamlinit\n(* ## added by OPAM user-setup for ocamltop / base ## 3ec62baf6f9c219ae06d9814069da862 ## you can edit, but keep this line *)\n#use "topfind";;\n(* ## end of OPAM user-setup addition for ocamltop / base ## keep this line *)\n#thread;;\n#require "core.top";;\n#require "core.syntax";;\nRun Code Online (Sandbox Code Playgroud)\n\n这是我已经安装核心的证据。
\n\nmymac:Desktop myusr$ opam install core utop\n[NOTE] Package utop is already installed (current version is 2.4.1).\n[NOTE] Package core is already installed (current version is v0.12.3).\nRun Code Online (Sandbox Code Playgroud)\n\n这是sum.ml来自Real World OCaml的文件:
mymac:Desktop myusr$ ocaml --version\nThe OCaml toplevel, version 4.08.1\nRun Code Online (Sandbox Code Playgroud)\n\n这是当我尝试使用以下命令构建它时会发生的情况corebuild:
mymac:Desktop myusr$ corebuild sum.native\n+ ocamlfind ocamlc -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -short-paths -thread -package core -ppx \'ppx-jane -as-ppx\' -o sum.cmo sum.ml\nFile "sum.ml", line 1, characters 5-13:\n1 | open Core.Std\n ^^^^^^^^\nError: Unbound module Core.Std\nCommand exited with code 2.\nHint: Recursive traversal of subdirectories was not enabled for this build,\n as the working directory does not look like an ocamlbuild project (no\n \'_tags\' or \'myocamlbuild.ml\' file). If you have modules in subdirectories,\n you should add the option "-r" or create an empty \'_tags\' file.\n\n To enable recursive traversal for some subdirectories only, you can use the\n following \'_tags\' file:\n\n true: -traverse\n <dir1> or <dir2>: traverse\n\nCompilation unsuccessful after building 2 targets (1 cached) in 00:00:00.\nRun Code Online (Sandbox Code Playgroud)\n\n为什么 corebuild 没有链接到核心库?我怎样才能解决这个问题?
\n构建脚本正确加载所有内容。您尝试加载的模块不再存在。您正在尝试将旧版本的 Real World OCaml 书与非常新版本的 OCaml 和 Core 一起使用。自那时以来,Janestreet Core 库发生了很大变化。您应该切换到较新的书籍或降级到旧版本的 OCaml 和核心库。
自从允许 Dune 和模块别名以来,不再需要额外的Std子模块,因此 Janestreet 删除了它(在长达两年的弃用之后)。因此,现在我们写
open Core
Run Code Online (Sandbox Code Playgroud)
代替
open Core.Std (* no longer works *)
Run Code Online (Sandbox Code Playgroud)
等人也是如此Core_kernel。
由于 OCaml 和 Janesteet 从那时起已经发生了很多变化,因此使用更新的示例创建了 RWO 的新版本。该工作仍在进行中,但看起来已经接近准备就绪。所以你可以切换到它。
如果您想使用 Real World OCaml 的第一个版本,那么您必须选择已知兼容的 OCaml 和 Janesteet 的核心库版本。我没有找到任何权威建议来说明哪个版本与旧书一起使用更好。所以我建议使用 OCaml 4.02.3。然后你可以像往常一样安装核心opam install core(它应该安装版本113.33.03),据我记得,它应该与旧书一起使用。如果您或其他人对此版本有疑问,请在评论部分告诉我,我将更新此建议。