0

My lib has two files: bson.ml and bson.mli.

I also have another test file which use let doc = Bson.make ();; etc to access the library and it is fine without any problem.

I also successfully build them and I get bson.cmx and bson.cmo


I then followed Where to place a shared utility module in OCaml? for ocamlfind install.

The META is like this:

name="bson"
description="A bson data structure, including encoding/decoding"
version="0.88.1"
archive(byte)="bson.cmo"
archive(native)="bson.cmx"

As instructed from the post above, the command I used is

ocamlfind install bson META _build/src/bson.cmx _build/src/bson.cmo src/bson.mli

It said

Removed /Users/xxx/.opam/4.00.1/lib/bson
Installed /Users/xxx/.opam/4.00.1/lib/bson/bson.mli
Installed /Users/xxx/.opam/4.00.1/lib/bson/bson.cmo
Installed /Users/xxx/.opam/4.00.1/lib/bson/bson.cmx
Installed /Users/xxx/.opam/4.00.1/lib/bson/META

If I use ocamlfind list, I can see it is there

bisect              (version: 1.3)
bson                (version: 0.88.1)
camlp4              (version: [distributed with Ocaml])

ok, then I open ocaml toplevel and #require "bson". It said

# #require "bson";;
/Users/xxx/.opam/4.00.1/lib/bson: added to search path
/Users/xxx/.opam/4.00.1/lib/bson/bson.cmo: loaded

finally, when I begin to use it let doc = Bson.make ();;, it sayd Error: Unbound module Bson.

Why?

I successfully installed my lib, why still can not use it?

Edit

I also tried load it via command line such as ocamlbuild -use-ocamlfind -package bson test.native, still does not work

Community
  • 1
  • 1
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271

1 Answers1

1

figured it out by myself.

I should also install the .cmi and .o files. If without .o file, native cannot be compiled.

I should use ocamlfind install bson META _build/src/bson.cmx _build/src/bson.cmo src/bson.mli _build/src/bson.cmi _build/src/bson.o

instead of ocamlfind install bson META _build/src/bson.cmx _build/src/bson.cmo src/bson.mli

i.e., add _build/src/bson.cmi _build/src/bson.o (Please see @gasche's comment below)

Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
  • 3
    You *must* install the `.cmi`, without wich the type-checker is not able to know what the module interface is, but you *should* also install the `.mli` for documentation purposes. Sorry for the error-inducing answer to the other post (I wrote the commands from memory without testing them); I edited it to correct the installation command. – gasche May 03 '13 at 06:18