Using Unix Functions in an OCaml Source

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

open Unix; (*declared at the top of the file*) let get_time () = Unix.gettimeofday () 

The corresponding entry in the .mli file is as follows:

 val get_time : unit -> float 

But when compiling, they cause an error:

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

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

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

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

 LD_LIBRARY_PATH=~/lib 

Other functions, such as fprintf from the Printf module, work correctly when located in the same / lib / ocaml directory.

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

+4
source share
3 answers

You should compile like this:

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

or

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

If you configured findlib correctly,

ocamlfind ocamlopt -package Unix -linkpkg time.ml

saves you from having to choose a .cma or .cmxa version.

+3
source

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

You did not carefully read the documentation.

eg. OCaml Tutorial: unix library or ocaml-tutorial: Compiling OCaml Projects

0
source

Source: https://habr.com/ru/post/1416533/


All Articles