OCaml graphics relies on X11. Out of the box 10.9 lacks X11. This site provides an ‘Apple approved’ version of X11 called “XQuartz”.

The shell command “ocamlmktop -o mytop graphics.cma” is necessary for OCaml graphics. As shipped it cannot find libX11.6.dylib. as explained here where we propose adding “export DYLD_LIBRARY_PATH=/opt/X11/lib” to the file .bash_profile . In 10.9, however, that addition causes XQuartz to fail.

Here is an awkward workaround:


Perhaps a better workaround: Without the export command in .bash_profile do shell command:
 ocamlmktop -o ~/bin/ocamlg graphics.cma
This should place a top level OCaml interpreter with the graphics functions where the shell command beginning ocamlg launches the interpreter but only in a shell launched while the export command is in .bash_profile.
The following four commands all produce the same error:
ocamlmktop -o mytop graphics.cma
ocamlmktop -o mytop -dllpath /opt/X11/lib graphics.cma
ocamlmktop -o mytop -dllpath /opt/X11 graphics.cma
ocamlmktop -o mytop -dllpath /opt/X11/lib/libX11.6.dylib graphics.cma
The error message is:
File "_none_", line 1:
Error: Error on dynamically loaded library: /usr/local/lib/ocaml/stublibs/dllgraphics.so: dlopen(/usr/local/lib/ocaml/stublibs/dllgraphics.so, 138): Library not loaded: /opt/local/lib/libX11.6.dylib
  Referenced from: /usr/local/lib/ocaml/stublibs/dllgraphics.so
  Reason: image not found

This is useful.