Graphics does not install on OPAM MacOS/HomeBrew with default switch

I observed an unexpected behavior on installing the Graphics library.

I am using MacOS High-Sierra 10.13.6 (17G65), with Opam 2.0.0, installed with HomeBrew.

I tried to install the Graphics library on the default switch, and it failed. See the trace below. However, it installs without any problem on any other switch, for instance 4.07.0+rc1.

This was somewhat disturbing. Is there any rationale behind?



$ opam switch default

$ opam install graphics
The following actions will be performed:
  ∗ install graphics 1.0

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫 

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫 
[ERROR] The compilation of graphics failed at "/Users/bouge/.opam/opam-init/hooks/ build ocamlc -custom graphics.cma -o test".
#=== ERROR while compiling graphics.1.0 =======================================#
# context     2.0.0 | macos/x86_64 | ocaml-system.4.07.0 |
# path        ~/.opam/default/.opam-switch/build/graphics.1.0
# command     ~/.opam/opam-init/hooks/ build ocamlc -custom graphics.cma -o test
# exit-code   2
# env-file    ~/.opam/log/graphics-92876-dd682e.env
# output-file ~/.opam/log/graphics-92876-dd682e.out
### output ###
# File "_none_", line 1:
# Error: Cannot find file graphics.cma
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫 
┌─ The following actions failed
│ λ build graphics 1.0
╶─ No changes have been performed
<><> graphics.1.0 troubleshooting <><><><><><><><><><><><><><><><><><><><><>  🐫 
=> This package checks whether the Graphics library was compiled.

If you’re using MacPorts with OPAM, you’re well advised not to use a system switch for any longer than it takes to compile a new switch. I suspect that the same is true on Homebrew.

1 Like

Yes. In the current version of opam 2.0.0 on brew ocaml is not even an dependency anymore, it is just required for building and testing so if you just get the precompiled version (“bottle”) then you don’t even install ocaml.

hi, I have the same problem like you. can you please tell me, what the solution is? Thank you. :blush:

Yes, do not use the system compiler but rather use an opam-built one:

opam switch create 4.07.1
opam install graphics
1 Like

Thanks for all your replies. I installed OPAM 2 and acted along your guidelines, and it work well.

However, I am still confused about the way to select the right opam-built one? How can you guess it is
4.07.1 and not one of the numerous versions listed by opam switch list-available?

It would be helpful to let the opam switch create define/suggest a default version for the dummy user.


On the original issue (installing graphics in a system compiler), there’s, but it’s stalled on a CI error.

Thanks. I cannot understand the whole discussion the link, but I think I can manage. Regards, Luc.

That PR has just been merged, so you can now build the graphics package without having to recompile OCaml

Excellent, thanks.

It will ease life for a large numbers of students… and TAs next year.