Graphics Installation in Opam

416 Views Asked by At

I am trying to install graphics using opam install graphics, but I get the following error message:

$ opam install graphics
The following actions will be performed:
  ∗ install   graphics     5.1.1
  ↻ recompile ocamlfind    1.9.1 [uses graphics]
  ↻ recompile base-bytes   base  [uses ocamlfind]
  ↻ recompile ounit2       2.2.4 [uses base-bytes]
  ↻ recompile ANSITerminal 0.8.2 [uses base-bytes]
===== ∗ 1   ↻ 4 =====
Do you want to continue? [Y/n] y

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><>   
[ANSITerminal.0.8.2] found in cache
[graphics.5.1.1] found in cache
[ocamlfind.1.9.1] found in cache
[ounit2.2.2.4] found in cache

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>   
[ERROR] The compilation of graphics failed at "/Users/traviszhang/.opam/opam-init/hooks/sandbox.sh build dune
        build -p graphics -j 3 @install".

#=== ERROR while compiling graphics.5.1.1 =====================================#
# context     2.0.8 | macos/x86_64 | ocaml-base-compiler.4.11.1 | https://opam.ocaml.org#7e6a6dcc
# path        ~/.opam/cs3110-2021sp/.opam-switch/build/graphics.5.1.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p graphics -j 3 @install
# exit-code   1
# env-file    ~/.opam/log/graphics-9364-8b8a2d.env
# output-file ~/.opam/log/graphics-9364-8b8a2d.out
### output ###
# [...]
# In file included from src/unix/subwindow.c:16:
# src/unix/libgraph.h:17:10: fatal error: 'X11/Xlib.h' file not found
# #include <X11/Xlib.h>
#          ^~~~~~~~~~~~
# 1 error generated.
#           cc src/text.o (exit 1)
# (cd _build/default/src && /usr/bin/cc -O2 -fno-strict-aliasing -fwrapv -D_FILE_OFFSET_BITS=64 -D_REENTRANT -g -I /Users/traviszhang/.opam/cs3110-2021sp/lib/ocaml -o text.o -c text.c)
# In file included from src/unix/text.c:16:
# src/unix/libgraph.h:17:10: fatal error: 'X11/Xlib.h' file not found
# #include <X11/Xlib.h>
#          ^~~~~~~~~~~~
# 1 error generated.



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>   
┌─ The following actions failed
│ λ build graphics 5.1.1
└─ 
╶─ No changes have been performed

I have tried the following solutions, but none of them seem to work:

  1. https://github.com/ocaml/graphics/issues/16 (running export LIBRARY_PATH=/opt/X11/lib)
  2. Also adding export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig" to my .zshrc file (this is mentioned in the same thread as 1.

When I run pkg-config --list-all | grep x11 the x11 libraries pop up, but for some reason spam can't seem to find it when trying to install graphics. Any suggestions would be helpful!

Here is my current computer configuration:

  • macOS BigSur Version 11.2.1
  • Ocaml Compiler 4.11.1

Update:

This issue has been brought up in the following thread (https://github.com/ocaml/graphics/pull/36#issuecomment-846827032), and will be updated in the new graphics release.

1

There are 1 best solutions below

1
On

The easiest path to get the graphics package working on macOS is to install and properly setup homebrew, after that you can just do

opam depext --install graphics

and it should install the system dependencies via homebrew (xquartz and xorgproto) and install the OCaml library.