2012-06-07 21 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版本的麻煩。