1

I tried to install the ocaml graphics package, but it fails. Any suggestions for how I can fix it?

~/Documents/Work/Code/OCaml with graphics: opam update

=-=- Updating package repositories =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=   
[default: http] Command started
[default: http] Command started
[default] synchronized from https://opam.ocaml.org

~/Documents/Work/Code/OCaml with graphics: opam upgrade
Already up-to-date.

~/Documents/Work/Code/OCaml with graphics: opam install graphics
The following actions will be performed:
  ∗  install graphics 1.0

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=   

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=   
[graphics: ocamlc graphics.cma] Command started
[ERROR] The compilation of graphics failed at "ocamlc -custom graphics.cma -o
        test".

#=== ERROR while installing graphics.1.0 ======================================#
# opam-version         1.2.2
# os                   darwin
# command              ocamlc -custom graphics.cma -o test
# path                 /Users/Tim/.opam/system/build/graphics.1.0
# compiler             system (4.04.0)
# exit-code            2
# env-file             /Users/Tim/.opam/system/build/graphics.1.0/graphics-14648-7afd23.env
# stdout-file          /Users/Tim/.opam/system/build/graphics.1.0/graphics-14648-7afd23.out
# stderr-file          /Users/Tim/.opam/system/build/graphics.1.0/graphics-14648-7afd23.err
### stderr ###
# File "_none_", line 1:
# Error: Cannot find file graphics.cma

=-=- Error report -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=   
The following actions failed
  ∗  install graphics 1.0
No changes have been performed

=-=- graphics.1.0 troubleshooting -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=   
=> This package checks whether the Graphics library was compiled.

Other than the missing graphics package, my ocaml install is working fine.

Here are the contents of the files in ~/.opam/system/build/graphics.1.0

First, graphics-14648-7afd23.err:

File "_none_", line 1:
Error: Cannot find file graphics.cma

Then graphics-14648-7afd23.info:

# opam-version         1.2.2
# os                   darwin
# command              ocamlc -custom graphics.cma -o test
# path                 /Users/Tim/.opam/system/build/graphics.1.0
# compiler             system (4.04.0)
# env-file             /Users/Tim/.opam/system/build/graphics.1.0/graphics-14648-7afd23.env
# stdout-file          /Users/Tim/.opam/system/build/graphics.1.0/graphics-14648-7afd23.out
# stderr-file          /Users/Tim/.opam/system/build/graphics.1.0/graphics-14648-7afd23.err

And graphics-14648-7afd23.env:

PATH=/Users/Tim/.opam/system/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/usr/local/bin
OCAML_TOPLEVEL_PATH=/Users/Tim/.opam/system/lib/toplevel
PERL5LIB=/Users/Tim/.opam/system/lib/perl5:
MANPATH=/Users/Tim/.opam/system/man:/opt/local/share/man:
OPAMSWITCH=system
OPAMUTF8MSGS=1
CAML_LD_LIBRARY_PATH=/Users/Tim/.opam/system/lib/stublibs:/usr/local/lib/ocaml/stublibs
SHELL=/bin/bash
TERM=dumb
TMPDIR=/var/folders/kv/kmn525v16kb2mz2hrhq3q4mh0000gn/T/
BASHRC_HAS_BEEN_RUN=1
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.8tP8Ej926f/Render
EMACSDATA=/Applications/Emacs.app/Contents/Resources/etc
OLDPWD=/Users/Tim/Documents/Work/Code
EMACSPATH=/Applications/Emacs.app/Contents/MacOS/bin
USER=Tim
EMACS=t
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.EXKwsf0Dz0/Listeners
TERMCAP=
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
COLUMNS=190
BASH_PROFILE_HAS_BEEN_RUN=1
PWD=/Users/Tim/Documents/Work/Code/OCaml with graphics
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
EMACSLOADPATH=/Applications/Emacs.app/Contents/Resources/site-lisp:/Applications/Emacs.app/Contents/Resources/lisp:/Applications/Emacs.app/Contents/Resources/leim
SHLVL=1
HOME=/Users/Tim
LOGNAME=Tim
INFOPATH=/Applications/Emacs.app/Contents/Resources/info:
DISPLAY=/private/tmp/com.apple.launchd.jPYPDR7RIj/org.macosforge.xquartz:0
INSIDE_EMACS=23.1.1,comint
EMACSDOC=/Applications/Emacs.app/Contents/Resources/etc
_=/usr/local/bin/opam
OPAM_PACKAGE_VERSION=1.0
OPAM_PACKAGE_NAME=graphics
MAKELEVEL=
MAKEFLAGS=

The final file, graphics-14648-7afd23.env, is empty.

Tim Leonard
  • 153
  • 6

1 Answers1

0

Edit: this answer didn't solve OP's problem. But I think this answer is still valuable, so I leave this here.


Install the OCaml compiler via OPAM, using opam switch <version number here> (Available version numbers are shown by opam switch). The graphics package is a virtual package to check the availability of the Graphics library, so opam install graphics will fail if there is no library on system's OCaml.

You can confirm the existence of the Graphics library by running ls ~/.opam/*/lib/ocaml/graphics.cma. If no file is found, then Graphics is not installed and therefore the failure of installation is the valid behavior. I don't know the exact reason why Graphics isn't installed, but maybe it's important that Graphics needs X11 to be installed. Especially, it's necessary to install XQuartz on macOS. See Shoe's answer for details. Also, re-installation of OCaml via OPAM will be needed after that. We can reinstall OCaml by running:

opam switch reinstall <version number here>
nekketsuuu
  • 1,641
  • 1
  • 21
  • 26
  • Thanks for the suggestion, but it doesn't seem to have helped. I get the same error with the same messages. – Tim Leonard Feb 14 '18 at 14:58
  • 3
    To summarize, `opam install graphics` only checks to see if the graphics library is built in. And it should be built in by `opam install ocaml`. But macOS doesn't include X11, and graphics requires X11, so I have to install XQuartz (the macOS version of X11) with `brew install Caskroom/cask/xquartz` (and then restart my computer), and then reinstall ocaml with `brew reinstall ocaml --with-x11`. Then the graphics library should be included in ocaml, and `opam install graphics` should verify that it's available. I tried it, and no joy: I still get `# Error: Cannot find file graphics.cma`. – Tim Leonard Feb 16 '18 at 17:03