`ocamlfind` not finding `opam` installed packages

I’m not an ocaml programmer, but I use or experiment with a few ocaml programs.

After happily makeing one program for years, I decided to explore another program. The new program recommended using opam switch (some kind of virtual environment similar to Python’s venv?) and I followed its instructions without issue. Now when I try to update the first program, it can’t find some packages where it previously had no problem. Even after (redundantly?) opam install the_so_called_unfindable_package, ocamlfind query the_so_called_unfindable_package is not found even though opam list | grep the_so_called_unfindable_package shows it. I find it particularly hilarious that ocamlfind query ocamlfind is not found.

Clearly, I lack a fundamental understanding of ocaml package management (and maybe the first program’s Makefile is somehow inadequate).

Other than unsetting the opam env variables to build the first program, how should ocaml programs be built in an opam switch when that was not mentioned in the install instructions nor Makefile?

Are you using an ocamlfind installed with opam, or a previously-installed one? If it was previously installed, it may be looking in a different package repository. You can find out by doing which ocamlfind and checking whether it lives in your opam switch (~/.opam).

Note that ocamlfind is not the package name, only the executable name. The package name is findlib.

Cheers,
Nicolas

1 Like

I think so.

$ opam switch
#  switch      compiler                    description
   bap_switch  ocaml-base-compiler.4.14.1  bap_switch
→  default     ocaml.4.14.1                default

$ which ocamlfind
~/.opam/default/bin/ocamlfind

$ ocamlfind query lablgtk3
ocamlfind: Package `lablgtk3' not found

$ opam show lablgtk3

<><> lablgtk3: information on all versions ><><><><><><><><><><><><><><><><><><>
name                   lablgtk3
all-installed-versions 3.1.3 [default]
...

I didn’t know that.

$ ocamlfind query findlib
/home/rick/.opam/bap_switch/lib/findlib

Ahhhh, interesting…

After hash -r, now ocamlfind query is finding the packages.
:+1:

That’s because it’s a different ocamlfind. Before the hash -r , you were running the ocamlfind from the default switch, and that’s why it wouldn’t find the packages in the bap_switch.

Thanks for asking a smart question.


Ian

Maybe opam should accommodate this behaviour. opam env sets PATH to tell the shell where to find executables. If a shell optimization is ignoring PATH and using cached locations, then maybe opam env should also set aliases to the full paths of the executables instead of setting the PATH.

This is also more explicit as it shows us exactly what executables are in each switch.

1 Like