Setting up an Ocaml library using 'ocamlfind install' and then using the library in ocamlbuild
ocaml, ocamlbuild, ocamlfind
Solution
See Section 11.1 of the OCaml Manual:
From the file x.ml, the ocamlopt compiler produces two files: x.o, containing native object code, and x.cmx, containing extra information for linking and optimization of the clients of the unit. The compiled implementation should always be referred to under the name x.cmx (when given a .o or .obj file, ocamlopt assumes that it contains code compiled from C, not from Caml).
Problem
I followed the instructions here for setting installing a library in site-lib using ocamlfind install. I had two libraries: one called logic and another called boolean. In each case I installed the .cmo, .cmx, .cmi and .mli files in the library, for example: ``` ocamlfind install boolean META boolean.cmo boolean.cmx boolean.cmi boolean.mli ``` Then when I went to build another project that depends on logic and boolean using ocamlbuild, I got the following error message: ``` $ocamlbuild -use-ocamlfind test_logic.native -classic-display ... /home/phil/godi-3.12.1.0/bin/ocamlfind ocamlopt -c -package boolean -package deriving- ocsigen -package deriving-ocsigen.syntax -package logic -package oUnit -package unix -syntax camlp4o -o test_logic.cmx test_logic.ml /home/phil/godi-3.12.1.0/bin/ocamlfind ocamlopt -linkpkg -linkpkg -package boolean -package deriving-ocsigen -package deriving-ocsigen.syntax -package logic -package oUnit -package unix -syntax camlp4o vhdl.cmx fsm.cmx test_logic.cmx -o test_logic.native + /home/phil/godi-3.12.1.0/bin/ocamlfind ocamlopt -linkpkg -linkpkg -package boolean -package deriving-ocsigen -package deriving-ocsigen.syntax -package logic -package oUnit -package unix -syntax camlp4o vhdl.cmx fsm.cmx test_logic.cmx -o test_logic.native gcc: /home/phil/godi-3.12.1.0/lib/ocaml/site-lib/logic/logic.o: No such file or directory gcc: /home/phil/godi-3.12.1.0/lib/ocaml/site-lib/boolean/boolean.o: No such file or directory File "caml_startup", line 1, characters 0-1: Error: Error during linking Command exited with code 2. ``` I then copied the .o files from the logic and boolean projects over to their respective areas in site-lib and it compiled and linked fine. I'm wondering why the .o files were needed and why gcc is involved here? Here's my _tags file in case it helps: ``` <*.ml> or "test_logic.native" or "test_loginc.byte": package(boolean),package(unix), package(oUnit), package(deriving-ocsigen), package(deriving-ocsigen.syntax), syntax(camlp4o), package(logic) ```