在OCaml源代码中使用Unix函数
我有一个函数,可以使用函数time.ml中的unix gettimeofday()获取当前时间。文件通过以下方式访问函数:在OCaml源代码中使用Unix函数,unix,ocaml,Unix,Ocaml,我有一个函数,可以使用函数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, character
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
并且路径被正确设置为in.bashrc文件
Printf模块中的其他函数(如fprintf)可以正常工作,尽管它们位于相同的/lib/ocaml目录中
有什么想法吗?我是做错了什么还是遗漏了什么?您必须这样编译:
ocamlc unix.cma -c time.mli time.ml (* bytecode *)
或
如果您有正确配置的findlib
ocamlfind ocamlopt-package Unix-linkpkg time.ml
这将省去您选择.cma或.cmxa版本的麻烦。>您知道哪里有问题吗?我是做错了什么还是错过了什么?您没有认真阅读文档。例如,或
ocamlc unix.cma -c time.mli time.ml (* bytecode *)
ocamlopt unix.cmxa -c time.mli time.ml (* native code *)