OCaml Graphics Error Unbound module mac OSX

515 Views Asked by At

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

There are 1 best solutions below

5
cuihtlauac On

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).