Skip to content

Instantly share code, notes, and snippets.

@squeuei
Last active March 14, 2019 11:39
Show Gist options
  • Save squeuei/61858ed207d59e593c40bcb7c4b1be40 to your computer and use it in GitHub Desktop.
Save squeuei/61858ed207d59e593c40bcb7c4b1be40 to your computer and use it in GitHub Desktop.
OCaml `Graphics` library and opam switch

Problem

For example, you installed OCaml 4.x.x compiler/environment via opam switch and tried to install graphics.

opam switch 4.x.x
# `opam switch create 4.x.x` if opam 2.0.0
eval `opam config env`
opam install graphics

You might encounter some errors like this.

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

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

Solution

The cause of this error is that the system lacks Graphics library as described in the error messages.

To solve this problem, you have to install OpenGL libraries before you switch the environment.

There is no Graphics library compiled if you haven't installed OpenGL libraries when you switched the environment.

As of 2018-06-02 and under the environment described below,

  • Fedora 28
  • System Compiler: OCaml 4.06.0 (Fedora Official Package)
  • Opam 2.0.0 beta6 (Fedora Official Package)
  • Switch: OCaml 4.06.1
  1. Remove the switch.
  2. Install OpenGL libraries (In my case sudo dnf install glew-devel worked)
  3. Create a switch
  4. Install Graphics

Here's what I typed.

opam switch remove 4.06.1
sudo dnf install glew-devel
opam switch create 4.06.1
opam $(opam env)
opam install graphics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment