2012-06-07 19 views
4

我有一个函数来获取当前时间使用unix gettimeofday()函数time.ml。该文件访问功能以下列方式:在OCaml中使用Unix函数源

open Unix; (*declared at the top of the file*) 

let get_time() = Unix.gettimeofday() 

.mli文件中的相应条目是这样的:

File "_none_", line 1, characters 0-1: 
No implementations provided for the following modules: 
Unix referenced from time.cmx 

val get_time : unit -> float 

但编译它们抛出一个错误时

我已检查以下文件是否存在于/lib/ocaml目录中:

unix.cmi, unix.a unix.cma unix.cmx unix.cmxa unix.cmxs unix.mli 

和路径设置正确设置为的.bashrc文件

LD_LIBRARY_PATH=~/lib 

其他功能,如fprintf中printf的模块正常工作inspite在同一/LIB/ocaml的目录之中。

任何想法可能是错的?我做错了什么,或者我错过了什么?

回答

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版本的麻烦。