我在用Ubuntu 18.04。我安装了OCaml 4.05 (通过apt-get)以及utop和核心 (通过opam)。这是我的~/.ocamlinit的内容
(* Added by OPAM. *)
let () =
try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
with Not_found -> ()
;;
#use "topfind";;
#thread;;
#camlp4o;;
#require "core.top";;
#require "core.syntax";;编译使用Core的OCaml代码可以很好地进行重构。但是,它不适用于普通的ocamlc或ocamlopt。他们抱怨:
错误:未绑定模块核心
我发现重建很挑剔。它不喜欢位于同一个目录中的任何现有的非OCaml代码:
SANITIZE: a total of 12 files that should probably not be in your source tree
has been found. A script shell file "/home/anta40/Codes/_build/sanitize.sh"
is being created. Check this script and run it to remove unwanted files or
use other options (such as defining hygiene exceptions or using the
-no-hygiene option).
IMPORTANT: I cannot work with leftover compiled files.
ERROR: Leftover object files:
File hellod.o in . has suffix .o
File helloscheme_.o in . has suffix .o
File nqueens.o in . has suffix .o
File helloscheme.o in . has suffix .o
File HelloHS.o in . has suffix .o
File helloml.o in . has suffix .o
ERROR: Leftover OCaml compilation files:
File nqueens.cmo in . has suffix .cmo
File helloml.cmo in . has suffix .cmo
File helloml.cmi in . has suffix .cmi
File nqueens.cmi in . has suffix .cmi
File nqueens.cmx in . has suffix .cmx
File helloml.cmx in . has suffix .cmx
Exiting due to hygiene violations.
Compilation unsuccessful after building 0 targets (0 cached) in 00:00:00.使用-no-hygiene选项,例如corebuild sum.ml -no-hygiene不会生成任何本机可执行文件。有什么解决办法吗?
发布于 2018-07-08 07:01:33
OPAM包管理器可以支持多个OCaml实例,其中每个组都是一个OCaml安装(ocaml、ocamlc、ocamlopt等)。已经安装的软件包。每个实例都被称为开关。
键入ocaml switch以查看实例列表。在交换机方面,使用软件包(Apt)安装OCaml称为系统。
我建议您创建一个新的交换机,确保OPAM设置的来源是正确的,并在其中安装新的交换机:
opam switch 4.06.1
eval $(opam config env)
opam install core自动生成工具假设它们控制整个构建过程,并在找到其他编译结果时发出抱怨。通常,运行建议的shell脚本并重新尝试附加步骤,即使只是为了发现另一个问题。您的第二个问题(使用-no-hygeine)可能与安装问题有关。
发布于 2018-07-08 19:27:54
你的装置已经过时了。
我猜想您在Real中遵循了指令,但是OCaml生态系统已经从RWO的第一版开始移动了。要获得现代安装,您应该遵循Real OCaml https://dev.realworldocaml.org/install.html的开发版本。
要回答您的问题,重构是ocamlbuild的一个很好的包装器。若要从具有重新构建功能的sum.ml生成可执行文件,应使用
重排sum.native
对于本机可执行文件或
重排sum.byte
用于字节码编译
否则,可以通过ocamlfind调用ocamlopt:
奥卡姆洛普-package核sum.ml
最后,如果您打算构建更大的项目,您应该看看沙丘https://jbuilder.readthedocs.io/en/latest/overview.html。
https://stackoverflow.com/questions/51223891
复制相似问题