# Problem linking library after upgrade

**URL:** <https://discuss.ocaml.org/t/problem-linking-library-after-upgrade/11667>\
**Category:** Learning\
**Created:** [March 14, 2023, 8:25pm UTC](https://discuss.ocaml.org/t/problem-linking-library-after-upgrade/11667 "2023-03-14T20:25:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TobyK](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TobyK](https://discuss.ocaml.org/u/TobyK)\
**Post date:** [March 14, 2023, 8:25pm UTC](https://discuss.ocaml.org/t/problem-linking-library-after-upgrade/11667/1 "2023-03-14T20:25:01Z")

</div>

I used to be able to compile programs using Big\_int with the command:

> $ ocamlopt -o test.opt nums.cmxa test.ml

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 test.ml

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 test.ml

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

CAML\_LD\_LIBRARY\_PATH=/home/user/.opam/ocaml.4.14.1/lib/stublibs:/home/user/.opam/ocaml.4.14.1/lib/ocaml/stublibs:/home/user/.opam/ocaml.4.14.1/lib/ocaml  
OCAML\_TOPLEVEL\_PATH=/home/user/.opam/ocaml.4.14.1/lib/toplevel  
OPAM\_SWITCH\_PREFIX=/home/user/.opam/ocaml.4.14.1  
PATH=/home/user/.opam/ocaml.4.14.1/bin: […]

How can I restore the previous behavior?

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [March 14, 2023, 9:32pm UTC](https://discuss.ocaml.org/t/problem-linking-library-after-upgrade/11667/2 "2023-03-14T21:32:20Z")

</div>

> [@TobyK](#):
>
> 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:

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

```

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![TobyK](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TobyK](https://discuss.ocaml.org/u/TobyK)\
**Post date:** [March 14, 2023, 11:27pm UTC](https://discuss.ocaml.org/t/problem-linking-library-after-upgrade/11667/3 "2023-03-14T23:27:52Z")

</div>

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

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