我有一个函数来使用函数 time.ml 中的unix gettimeofday()来获取当前时间。该文件以下列方式访问该函数:
open Unix; (*declared at the top of the file*)
let get_time () = Unix.gettimeofday ()
.mli 文件中的相应条目如下:
val get_time : unit -> float
但是在编译期间会抛出错误:
File "_none_", line 1, characters 0-1:
No implementations provided for the following modules:
Unix referenced from time.cmx
我已检查 / lib / ocaml 目录中是否存在以下文件:
unix.cmi, unix.a unix.cma unix.cmx unix.cmxa unix.cmxs unix.mli
并在 .bashrc 文件中正确设置路径。
LD_LIBRARY_PATH=~/lib
来自 Printf 模块的 fprintf 等其他功能正常工作,尽管它们位于相同的 / lib / ocaml 目录中。
任何想法都可能出错?我做错了什么或者我错过了什么?
答案 0 :(得分:6)
你必须像这样编译:
ocamlc unix.cma -c time.mli time.ml (* bytecode *)
或
ocamlopt unix.cmxa -c time.mli time.ml (* native code *)
答案 1 :(得分:3)
如果您有正确配置的findlib,
ocamlfind ocamlopt -package Unix -linkpkg time.ml
将为您省去选择.cma或.cmxa版本的麻烦。