Access the Unix package during compilation via ocamlfind ocamlc

The ocamlfind utility is a great tool to automatically add libraries during compilation, which exempts developers to pass directly the paths to those libraries, e.g., instead of doing

$ ocamlc -I ~/.opam/4.06.0/lib/thepackage -o prog

we do

$ ocamlfind ocamlc -package thepackage -o prog

cool. This works for 3rd party packages found via

$ ocamlfind list

but what about packages distributed with OCaml, like unix, which are also listed via the previous command? For example, if my program at the beginning does

open Unix
open Uutf

compiling it by passing unix and uutf in the package option to ocamlfind, works for uutf but for unix gives the result

$ ocamlfind ocamlc -package unix,uutf -o prog
File "", line 1:
Error: Required module `Unix' is unavailable

Only if I do

$ ocamlfind ocamlc -package uutf unix.cma -o prog

it works, which seems at least “strange” …

Everything listed by

$ ocamlfind list

should be searchable by this tool when passed via -package option.

What am I doing wrong?

When you do linking (no -c flag) try to add -linkpkg option.
There is also a nice -verbose option to be able to see what is actually being executed.

The -linkpkg option worked like a charm, and -verbose is nice to learn what is happening under the hood. For reference it worked with this command:

$ ocamlfind ocamlc -linkpkg -package unix,uutf -o prog

Thanks for this :+1: