Problem linking library after upgrade

I used to be able to compile programs using Big_int with the command:

$ ocamlopt -o test.opt nums.cmxa

and not worry about the library version, but now I’ve upgraded to 14.4.1 (with opam switch create ocaml.4.14.1; opam switch ocaml.4.14.1; opam install zarith) when I try to compile a program using Zarith (which replaced Num and Big_int) using

$ ocamlopt -o test.opt zarith.cmxa

I get an ‘Unbound module Z’ error. I now have to use ocamlfind or give a specific versioned path:

$ ocamlopt.opt -o test.opt -I /home/user/.opam/ocaml.4.14.1/lib/zarith zarith.cmxa

I’ve rerun eval $(opam config env) but no change. My environmental variables look OK:

PATH=/home/user/.opam/ocaml.4.14.1/bin: […]

How can I restore the previous behavior?

You can’t.

The old num library used to be part of the compiler distribution so it was installed next to the standard library. This is why you could avoid passing the -I flag and did not need to tell the compiler where to find nums.cmxa. But zarith is not (and has never been) part of the compiler distribution, so you must tell the compiler where to find zarith.cmxa.

You already mentioned ocamlfind, so you probably know how to use it to avoid hardcoding the path to the directory containing zarith.cmxa on the command-line, but for the benefit of other people, I’ll just spell it out:

$ ocamlopt -o test.opt -I `ocamlfind query zarith` zarith.cmxa


1 Like

Thanks, that looks to be a clearer way of using ocamlfind than I found:

$ ocamlfind ocamlopt -o test.opt -linkpkg -package zarith