我有一个文件main.ml
使用了一些使命令ocaml main.ml
失败并报告此错误的包:
Error: Unbound module X
到目前为止,我发现的唯一解决方案是运行:
ocamlbuild main.native -use-ocamlfind -package X
./main.native
但这会编译文件。有没有办法只运行ocaml main.ml
带有一些附加标志的常规 ocaml 解释器 () 以使其找到包?
最简单的方法可能是使用 topfind 并#require "core"
在文件顶部添加。如果您想避免在文件中添加顶级指令,您可以使用它ocamlfind query -i-format -r
来计算所需的包含目录:
ocaml $(ocamlfind query -i-format -r core) main.ml
您可以在文件的开头放置一些查找和加载所需模块的顶级指令。例如,当我想Core
在我的脚本中使用库时,我插入:
#use "topfind";;
#thread;;
#require "core";;
open Core.Std
(* Code of my script *)
要使用topfind
包ocamlfind
必须安装(opam install ocamlfind
)
您还可以查询包的路径到 ocamlfind :
ocamlfind query package_X
这将返回你的包的路径:/path_to/packageX
接着 :
ocaml main.ml -I /path_to/packageX