簡體   English   中英

在OCaml源代碼中使用Unix函數

[英]using Unix functions in OCaml source

我有一個函數來使用函數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

盡管存在於同一個/ lib / ocaml目錄中,但來自Printf模塊的fprintf等其他函數也能正常工作。

什么想法可能是錯的? 我做錯了什么或者我錯過了什么?

你必須像這樣編譯:

ocamlc unix.cma -c time.mli time.ml (* bytecode *)

要么

ocamlopt unix.cmxa -c time.mli time.ml  (* native code *)

如果你有一個正確配置的findlib,

ocamlfind ocamlopt -package Unix -linkpkg time.ml

將為您省去選擇.cma或.cmxa版本的麻煩。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM