I (re-)installed Ocaml on OS X using the following steps:
> brew uninstall ocaml
> brew uninstall opam
> brew install ocaml
> brew install opam
> opam init
> eval `opam config env`
> opam switch 4.02.1
> opam install batteries core
I then tried to compile this program:
open Unix
open Printf
let main () =
match fork () with
| 0 -> printf "child\n"
| pid -> printf "parent\n"
let _ = main ()
I compiled using this command:
ocamlc -o fork fork.ml
But I get an error:
File "fork.ml", line 1:
Error: Error while linking fork.cmo:
Reference to undefined global `Unix'
In fact, I was getting this error before reinstalling; that is why I reinstalled in the first place. But the problem persists and I am not sure how to fix it.