4
votes

I have a function to get the current time using the unix gettimeofday() in function time.ml. The file accesses the function in the following way:

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

let get_time ()  = Unix.gettimeofday ()

The corresponding entry in .mli file is like this:

val get_time : unit -> float

But during compiling them throws an error:

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

I have checked that the following files are present in /lib/ocaml directory:

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

and the path is set correctly set to in .bashrc file.

LD_LIBRARY_PATH=~/lib

Other functions like fprintf from Printf module work correctly inspite of being in the same /lib/ocaml directory.

Any ideas what could be wrong? Am I doing something wrong or am I missing something?

2
> Any ideas what could be wrong? Am I doing something wrong or am I > missing something? You didn't read the documentation attentively. E.g. OCaml manual : The unix library or ocaml-tutorial : Compiling OCaml projects - ygrek

2 Answers

6
votes

You have to compile like this:

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

or

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

If you have a properly configured findlib,

ocamlfind ocamlopt -package Unix -linkpkg time.ml

will save you the trouble of picking the .cma or the .cmxa version.