2
votes

I'm on OSX 10.11.6 (and sometimes 10.13.6). I've done the following (per https://stackoverflow.com/a/29609483/2630028):

brew install Caskroom/cask/xquartz
brew install ocaml
brew install pkg-config
brew install opam
opam install utop
opam install graphics

All commands are successful. Unfortunately there is no longer a --with-x11 flag with the ocaml brew formula. I tried to follow this doc: https://ocaml.org/learn/tutorials/structure_of_ocaml_programs.html#Modules-and-open.

In utop:

utop # #load "graphics.cma";;
Cannot find file graphics.cma.

In a foo.ml file

open Graphics;;

and running ocamlbuild foo.native:

File "foo.ml", line 1, characters 5-13:
1 | open Graphics;;
         ^^^^^^^^
Error: Unbound module Graphics
Command exited with code 2.

Is there any way to get this working without having to build from source?

1
Installing ocaml compiler via opam will be the most reliable. The system switches (ocaml compilers provided by macports, homebrew, apt, etc) have been discouraged for quite some time now since they can have some issues like the one you are seeing. - Anurag Soni

1 Answers

0
votes

Have you tried something like this?

utop -I $(ocamlfind query graphics)

It worked for me. You may need to adapt the syntax to your shell (here bash).