Ocaml can't find Unix module Ocaml can't find Unix module unix unix

Ocaml can't find Unix module


unix library is not linked by default, so you need to pass some linking flags, to make it work, e.g.,

 ocamlc unix.cma fork.ml -o fork

If you don't want to know anything about cma, you can use ocamlbuild, instead of ocamlc:

 ocamlbuild -lib unix fork.native

Or even more general

 ocamlbuild -pkg unix fork.native

The latter (with pkg option) would be a preferred way, since it will allow you to specify any package installed with opam. E.g., if you would ever try to use lwt, the you can just link with it with

 ocamlbuild -pkg lwt fork.native


For those getting this error while using the OCaml interactive toplevel, the command line syntax is similar to that required by ocamlc:

ocaml unix.cma