installing an Ocaml hump library on mutualized ser

2019-07-19 03:31发布

问题:

I am trying to use the Ocaml csv library. I downloaded csv-1.2.3 and followed the installation instructions after installing findlib:

  1. Uncompress the source archive and go to the root of the package,
  2. Run 'ocaml setup.ml -configure',
  3. Run 'ocaml setup.ml -build',
  4. Run 'ocaml setup.ml -install'

Now I have META, csv.a, csv.cma, csv.cmi, csv.cmx, csv.cmxa, csv.mli files in ~/opt/lib/ocaml/site-lib/csv repertory. The shell command ocamlfind list -describe gives csv A pure OCaml library to read and write CSV files. (version: 1.2.3) which I believe means that csv is installed properly.

BUT when I add

  let data = Csv.load "foo.csv" in

in my compute.ml module and try to compile it within the larger program package I have the compilation error :

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

and if I simply type

let data = load "foo.csv" in

i get :

File "compute.ml", line 74, characters 13-17:
Error: Unbound value load

I have the same type of errors when I use Csv.load or load directly in the Ocaml terminal. Would somebody have an idea of what is wrong in my code or library installation?

回答1:

My guess is that you're using ocamlfind for compilation (ocamlfind ocamlc -package csv ...), because you have a linking error, not a type-checking one (which would be the case if you had not specified at all where csv is). The solution may be, in this case, to add a -linkall option to the final compilation line producing an executable, to ask it to link csv.cmx with it. Otherwise, please try to use ocamlfind and yes, tell us what your compilation command is.

For the toplevel, it is very easy to use ocamlfind from it. Watch this toplevel interaction:

% ocaml
        Objective Caml version 3.12.1

# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

- : unit = ()
# #require "csv";;
/usr/lib/ocaml/csv: added to search path
/usr/lib/ocaml/csv/csv.cma: loaded
# Csv.load;;
- : ?separator:char -> ?excel_tricks:bool -> string -> Csv.t = <fun>

To be explicit. What I typed once in the toplevel was:

#use "topfind";;
#require "csv";;
Csv.load;; (* or anything else that uses Csv *)