我已经安装了opam
,运行opam init
,运行opam switch 4.06.0
创建了 4.06.0
~/.opam
里面的目录,运行“eval opam confing env
”,导出 $OCAML_TOPLEVEL_PATH
如~/.opam/4.06.0/lib/toplevel
除其他事项外,启动时ocaml
我得到了可怕的:
$ ocaml
OCaml version 4.06.0
Cannot find file topfind.
Unknown directive `camlp4o'.
#
我看过this和 this这两个都没有解决我的问题,我已经束手无策了(第一次设置 OCaml)。这是我的~/.ocamlinit
:
(* Added by OPAM. *)
let () =
try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
with Not_found -> ()
;;
#use "topfind"
#camlp4o
#thread
#require "core.top"
#require "core.syntax"
编辑:看起来我还没有安装 core
,安装core
解决了这个问题,但现在在大量的导入诊断中我得到了:
Exception:
Invalid_argument
"The ocamltoplevel.cma library from compiler-libs cannot be loaded inside the OCaml toplevel".
然后再往下一点:
Raised at file "pervasives.ml", line 33, characters 25-45
Called from file "toplevel/toploop.ml", line 468, characters 4-128
Called from file "toplevel/topdirs.ml", line 144, characters 10-51
Camlp4 Parsing version 4.06.0
最佳答案
你应该运行
eval `opam config env`
注意反引号。在大多数现代键盘上,它们通常位于 1
键的左侧。该命令不应输出任何内容,如果您看到任何输出,则意味着您运行不正确。每次启动新 shell 时都必须运行此命令来激活 opam 安装(除非您已将此命令放入 shell 初始化脚本中,例如 .bashrc
)
如果问题仍然存在,请确保您已安装 ocamlfind
软件包,
opam install ocamlfind
关于ocaml命令行找不到 “topfind”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47508389/