# Graphics package?

**URL:** <https://discuss.ocaml.org/t/graphics-package/1073>\
**Category:** Learning\
**Created:** [November 5, 2017, 8:57pm UTC](https://discuss.ocaml.org/t/graphics-package/1073 "2017-11-05T20:57:48Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![iru](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@iru](https://discuss.ocaml.org/u/iru)\
**Post date:** [November 5, 2017, 8:57pm UTC](https://discuss.ocaml.org/t/graphics-package/1073/1 "2017-11-05T20:57:48Z")

</div>

Environment: Linux Mint 18.2, Ocaml 4.05, Opam 1.2.

Gentlefolk,  
I have installed Opam (and OCaml) via the “debian” instructions from "  
[https://opam.ocaml.org/doc/Install.html](https://opam.ocaml.org/doc/Install.html).

Opam and OCaml work well but there is no graphics (Graphics.cma, etc).

A Google search shows numerous comments about the graphics package being “optional” and difficult to install.

Any help/direction appreciated, Ian.

---

<div class="post-metadata">

**Author:** ![theindigamer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/theindigamer/32/610_2.png) [@theindigamer](https://discuss.ocaml.org/u/theindigamer)\
**Post date:** [November 5, 2017, 10:36pm UTC](https://discuss.ocaml.org/t/graphics-package/1073/2 "2017-11-05T22:36:41Z")

</div>

Did you try the suggestions [here](https://stackoverflow.com/questions/29173582/ocaml-cannot-find-graphics-cma)? What do you get?

---

<div class="post-metadata">

**Author:** ![iru](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@iru](https://discuss.ocaml.org/u/iru)\
**Post date:** [November 6, 2017, 9:58am UTC](https://discuss.ocaml.org/t/graphics-package/1073/3 "2017-11-06T09:58:42Z")

</div>

Thank you for the response.

I viewed that article and tried the ls where… Graphics files found  
Tried the toplevel

# #use “topfind”;; \<\< Appears to have worked - no errors.

# #require “graphics”;; \<\< Error, not found.

As I have been changing things I decided start again with a clean version of Mint.  
Loaded a clean version of Mint 18.2, applied all updates.  
Performed sudo apt-get update, upgrade  
Installed opam and ocaml (04.05.0) from the opam and ocaml directions.

Tried the “ls where…” No graphics files found!!!

So somehow I have gone backwards. It looks like my attempts to install opam/ocaml have resulted in incomplete systems.

Any suggestions appreciated, Ian.

---

<div class="post-metadata">

**Author:** ![theindigamer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/theindigamer/32/610_2.png) [@theindigamer](https://discuss.ocaml.org/u/theindigamer)\
**Post date:** [November 6, 2017, 3:32pm UTC](https://discuss.ocaml.org/t/graphics-package/1073/4 "2017-11-06T15:32:58Z")

</div>

The page you’ve linked to only has instructions on installing opam. How did you install OCaml? Perhaps the installation source you were using was incomplete?

Regardless, you could try a fresh install:

```bash
opam update
opam switch 4.05.0-new --alias-of=4.05.0
# This will perform a fresh install of the compiler.
# This installation will take a while, so grab a coffee or something.
eval `opam config env` # switches to the version just installed

```

If you try the `ls ...` or (do `opam install utop` followed by) the topfind check, it should work (fingers crossed!).

---

<div class="post-metadata">

**Author:** ![iru](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@iru](https://discuss.ocaml.org/u/iru)\
**Post date:** [November 6, 2017, 10:35pm UTC](https://discuss.ocaml.org/t/graphics-package/1073/5 "2017-11-06T22:35:55Z")

</div>

Thanks for the instructions. However no success.

Started with a clean build of Linux Mint 18.2 and then performed the OPAM OCAML install.

Some steps were not the same as what you provided but the result should be the same…  
(I was viewing your email on my phone and miss-understood the use of the --alias-of=4.05.0)

The ocaml compiler was loaded from [https://github.com/ocaml/ocaml/archive/4.05.0.tar.gz](https://github.com/ocaml/ocaml/archive/4.05.0.tar.gz)

The following is an edited version of the opam ocaml install process (I tried to attach it as a text file but only graphics (ironic?) file types can be uploaded).

---

<div class="post-metadata">

**Author:** ![theindigamer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/theindigamer/32/610_2.png) [@theindigamer](https://discuss.ocaml.org/u/theindigamer)\
**Post date:** [November 8, 2017, 2:48am UTC](https://discuss.ocaml.org/t/graphics-package/1073/6 "2017-11-08T02:48:06Z")

</div>

> Some steps were not the same as what you provided but the result should be the same…

I’m sorry if I wasn’t clear enough, I was asking you to try doing a fresh install (which I did try on my machine and it did work) and see how that goes, instead of going about repairing your current installation.

Your first line is “Thanks for the instructions. However no success.”, so I’m not sure if you actually did the reinstall as I suggested or you didn’t… are you saying that earlier you weren’t following the `opam switch` steps and later you did and neither worked?

I looked at the linked tar.gz file and it does have the graphics files, so maybe the installation from source didn’t proceed correctly. In my experience, using an opam switch is much easier than installing from source using the tarball…

For a text file, you could just copy-paste it here if you can’t upload it.

---

<div class="post-metadata">

**Author:** ![dra27](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dra27/32/5294_2.png) [@dra27](https://discuss.ocaml.org/u/dra27)\
**Post date:** [November 8, 2017, 10:36pm UTC](https://discuss.ocaml.org/t/graphics-package/1073/7 "2017-11-08T22:36:42Z")

</div>

Do you have X11 headers installed (I’m not familiar with Linux Mint - you’ll want some kind of libx11-devel package)? opam-repository doesn’t track whether the base compiler actually built graphics. You can experiment with whether you have the correct headers by cloning the OCaml [GitHub Repo](https://github.com/ocaml/ocaml) and running ./configure to see if it will build the graphics library.

---

<div class="post-metadata">

**Author:** ![iru](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@iru](https://discuss.ocaml.org/u/iru)\
**Post date:** [November 9, 2017, 12:15am UTC](https://discuss.ocaml.org/t/graphics-package/1073/8 "2017-11-09T00:15:11Z")

</div>

Gentlefolk,

Thank you for your patience and persistence. The problem appears to be that the gcc compiler cannot compile a test file during the OPAN-Ocaml install.

My test/install process is:

New Mint18.2 install, all updates applied.

iru@ian-HP ~ $ gcc --version  
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609

// Update gcc to version 6  
sudo add-apt-repository ppa:ubuntu-toolchain-r/test  
sudo apt update  
sudo apt install gcc-6

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60

// From the OPAM install instructions  
// wget ://raw.github.com/ocaml/opam/master/shell/opam\_installer.sh -O - | sh -s /usr/local/bin

// Results (edited)  
// Location: ://raw.githubusercontent.com/ocaml/opam/master/shell/opam\_installer.sh [following]  
…  
…  
Downloading opam…  
You don’t have write access to /usr/local/bin: sudo may ask for your password  
Initializing with compiler 4.05.0  
Checking for available remotes: rsync and local.  
…  
…  
[WARNING] Recommended external solver aspcud not found.

=-=- Fetching repository information =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  
[default] synchronized from [https://opam.ocaml.org](https://opam.ocaml.org)

=-=- Installing compiler 4.05.0 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  
[compiler.get] [https://github.com/ocaml/ocaml/archive/4.05.0.tar.gz](https://github.com/ocaml/ocaml/archive/4.05.0.tar.gz) downloaded  
Now compiling OCaml. This may take a while, please bear with us…  
[ERROR] Compiler build failed at “./configure -prefix /home/iru/.opam/4.05.0  
-with-debug-runtime”:  
# opam-version 1.2.2  
# os linux  
# command ./configure -prefix /home/iru/.opam/4.05.0  
-with-debug-runtime  
# path /home/iru/.opam/4.05.0/build/ocaml  
# exit-code 2  
# env-file /home/iru/.opam/log/log-20385-cc66ff.env  
# stdout-file /home/iru/.opam/log/log-20385-cc66ff.out  
# stderr-file /home/iru/.opam/log/log-20385-cc66ff.err  
### stdout ###  
# Configuring OCaml version 4.05.0  
# Configuring for host x86\_64-unknown-linux-gnu …  
# Configuring for target x86\_64-unknown-linux-gnu …  
# Using compiler gcc.  
# Compiler family and version: gcc-6-3.  
# [ERROR!] Unable to compile the test program.  
# Make sure the C compiler gcc is properly installed.

[ERROR] Initialisation failed  
OpamGlobals.Exit(66)

// Notes:  
On a previous attempt to install OPAM it failed with the same error but specified the gcc-5.4 compiler. I performed a clean install and updated gcc in an attempt to overcome that issue.

So this is how I wind up with OPAM installed but no Ocaml.

Looking at the script (with some added ‘echos’ to trace things):  
// ://raw.githubusercontent.com/ocaml/opam/master/shell/opam\_installer.sh

The problem occurs in the following.  
if [“$(id -u)” = “0”]; then  
echo "Running as super-user: not running opam initialization.“  
echo “You’ll want to run “$OPAM init --comp $COMP” as user"  
else  
echo “Initializing with compiler $COMP”  
”$OPAM” init --comp “$COMP”

I will try and get into the following files and see what is the problem/s.

# env-file /home/iru/.opam/log/log-20385-cc66ff.env

```
    # stdout-file /home/iru/.opam/log/log-20385-cc66ff.out
    # stderr-file /home/iru/.opam/log/log-20385-cc66ff.err
```

---

<div class="post-metadata">

**Author:** ![dra27](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dra27/32/5294_2.png) [@dra27](https://discuss.ocaml.org/u/dra27)\
**Post date:** [November 9, 2017, 11:29am UTC](https://discuss.ocaml.org/t/graphics-package/1073/9 "2017-11-09T11:29:18Z")

</div>

Are you able to compile even a simple hello world application with your installation of GCC?

```auto
#include <stdio.h>

int main (void) {
  printf("Hello world\n");
}

```

?

---

<div class="post-metadata">

**Author:** ![dra27](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dra27/32/5294_2.png) [@dra27](https://discuss.ocaml.org/u/dra27)\
**Post date:** [November 9, 2017, 11:30am UTC](https://discuss.ocaml.org/t/graphics-package/1073/10 "2017-11-09T11:30:14Z")

</div>

To amend my previous answer slightly, Opam does have a misnamed graphics package - so if you get further, `opam install graphics` will succeed only if your compiler was built with `graphics.cma`

---

<div class="post-metadata">

**Author:** ![iru](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@iru](https://discuss.ocaml.org/u/iru)\
**Post date:** [November 9, 2017, 11:07pm UTC](https://discuss.ocaml.org/t/graphics-package/1073/11 "2017-11-09T23:07:45Z")

</div>

Gentlefolk,

Some progress: Clean build of Mint 18.2, all updates, etc.

Following the suggestion of dra27 I checked the C compiler.  
Version 5.5 installed. Tried the small test program.

It failed complaining about problems with stdio.h.

Some research and ‘sudo apt-get install build-essentials’ fixed things. Clean compile.

Installed OPAM and OCAML by

wget [https://raw.github.com/ocaml/opam/master/shell/opam\_installer.sh](https://raw.github.com/ocaml/opam/master/shell/opam_installer.sh) -O - | sh -s /usr/local/bin

All good: ‘opam switch list’ shows compiler/s with 4.05.0 highlighted.

Unfortunately NO graphics!!! ls `ocamlc -where`/graphics\* cant find any graphics files in/with  
/home/iru/.opam/4.05.0/lib/ocaml/graphics\*

I think I am back to where I started - no graphics!

So where do we go from here now that I appear to have a good reproducible Linux-GCC-OPAM-OCAML environment???

Thanks for all the help, Ian.

---

<div class="post-metadata">

**Author:** ![dra27](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dra27/32/5294_2.png) [@dra27](https://discuss.ocaml.org/u/dra27)\
**Post date:** [November 10, 2017, 11:47am UTC](https://discuss.ocaml.org/t/graphics-package/1073/12 "2017-11-10T11:47:14Z")

</div>

Progress - back with working OCaml! Now if you clone [https://github.com/ocaml/ocaml.git](https://github.com/ocaml/ocaml.git) and then run `./configure` in the clone, I reckon you’re going to find that it complains that it can’t find X11 headers. There will be a package to install the X11 development headers in your package manager - try installing that and re-run configure. Once configure tells you that it will build the graphics library (IIRC it’s explicitly noted in the summary at the end, if not then look for graphics in the OTHERLIBRARIES value in `config/Makefile` after running configure) then you will need to rebuild your ocaml switch.

Again, I don’t know exactly how mint works, but the stock compiler installed is probably a “nox” variant - there may be a package which can be installed with X support - and hence graphics.cma

---

<div class="post-metadata">

**Author:** ![iru](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@iru](https://discuss.ocaml.org/u/iru)\
**Post date:** [November 11, 2017, 10:43am UTC](https://discuss.ocaml.org/t/graphics-package/1073/13 "2017-11-11T10:43:06Z")

</div>

Progress - I think…

I was not sure about [https://github.com/ocaml/ocaml.git](https://github.com/ocaml/ocaml.git) to download and install ocaml.  
Did I perform this on a system where I already had opam and ocaml installed or on a clean system?

Built a new Mint 18.2  
Used the Mint software manager to update the system. All went well.

Used the following to get required bits and pieces:

sudo apt-get update  
sudo apt-get upgrade  
sudo apt-get install build-essential  
sudo apt-get install libx11-dev  
sudo apt-get install aspcud

Downloaded and extracted: [https://github.com/ocaml/ocaml.git](https://github.com/ocaml/ocaml.git)

Used ./configure. Looks good. .

Output shows (edited)  
Configuring OCaml version 4.07.0+dev0-2017-09-18  
Configuring for host x86\_64-unknown-linux-gnu …  
Configuring for target x86\_64-unknown-linux-gnu …  
Using compiler gcc.  
Compiler family and version: gcc-5-4.

X11 works  
Options for compiling for X11:  
Options for linking with X11: -lX11

Directories where OCaml will be installed:  
binaries… /usr/local/bin  
standard library… /usr/local/lib/ocaml  
manual pages… /usr/local/man (with extension .1)

I also note the following:

Additional libraries supported:  
unix str dynlink bigarray raw\_spacetime\_lib systhreads threads graph  
Configuration for the “graph” library:  
options for compiling …  
options for linking … -lX11

I am also puzzled over the difference between ‘graph’ and ‘graphics’.

However, my main problem is where is ocaml??? Was it installed?  
I cannot find anything like an ‘ocaml executable’.  
When I check /usr/local/bin there is no sign of ocaml!!!

So it looks like some sort of progress, I think… I am certainly learning a lot…

Any help appreciated, Ian.

---

<div class="post-metadata">

**Author:** ![cfcs](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cfcs/32/833_2.png) [@cfcs](https://discuss.ocaml.org/u/cfcs)\
**Post date:** [November 11, 2017, 3:50pm UTC](https://discuss.ocaml.org/t/graphics-package/1073/14 "2017-11-11T15:50:29Z")

</div>

did you run `make` after you ran `./configure`?

---

<div class="post-metadata">

**Author:** ![lpw25](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lpw25/32/144_2.png) [@lpw25](https://discuss.ocaml.org/u/lpw25)\
**Post date:** [November 11, 2017, 5:30pm UTC](https://discuss.ocaml.org/t/graphics-package/1073/15 "2017-11-11T17:30:24Z")

</div>

To be clear dra27 doesn’t want you to try and install OCaml from the sources, he just wanted to see the output of the configure step to see if you had the right libraries installed. Since you now seem to have them I would suggest doing `opam switch reinstall 4.05.0` to make the OCaml you built with opam reinstall itself and, hopefully, install the graphics library.

---

<div class="post-metadata">

**Author:** ![iru](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@iru](https://discuss.ocaml.org/u/iru)\
**Post date:** [November 11, 2017, 7:40pm UTC](https://discuss.ocaml.org/t/graphics-package/1073/16 "2017-11-11T19:40:20Z")

</div>

Gentlefolk,  
Thank you all for the responses. Perhaps I should put the brain into gear and even read the documentation…

Read the install.adoc.Performed a couple of ‘makes’ and voila… Graphics modules in  
/usr/local/lib/ocaml/. Can invoke ocaml.

Will tidy things up with opam/ocaml and hopefully do something constructive.

Once again thank you all, Ian.

---

<div class="post-metadata">

**Author:** ![iru](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@iru](https://discuss.ocaml.org/u/iru)\
**Post date:** [November 12, 2017, 11:22am UTC](https://discuss.ocaml.org/t/graphics-package/1073/17 "2017-11-12T11:22:09Z")

</div>

Gentlefolk,

Everything is not quite right…

Using Geany as an IDE with a small graphics routine in a file which contains (first line):  
open Graphics;;

Looking at the Geany ‘Build’ commands.

‘Compile’ is ‘ocamlc -c %f’ — compile the file \<\<\<\< COMPILES OK - NO ERRORS  
’Build’ is ‘ocamlc -o %e %f — build-link the program \<\<\<\< FAILS - Error: Required module `Graphics’ is unavailable.

So there is a problem with the ‘linker’ or the linker has a different view of the ocaml world than the compiler.

Outside of Geany the following occurs in CLI:

iru@ian-HP ~/Projects $ ocamlc -o [ocaml1.ml](http://ocaml1.ml) ocaml1.cmo  
File “_none_”, line 1:  
Error: Required module `Graphics’ is unavailable

I chase on… Ian

---

<div class="post-metadata">

**Author:** ![cfcs](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cfcs/32/833_2.png) [@cfcs](https://discuss.ocaml.org/u/cfcs)\
**Post date:** [November 12, 2017, 2:30pm UTC](https://discuss.ocaml.org/t/graphics-package/1073/18 "2017-11-12T14:30:22Z")

</div>

@iru you need to explicitly link it.

`a.ml`:

```ocaml
let () = Graphics.open_graph "a"

```

```auto
$ ocamlc -o a.exe a.ml
File "a.ml", line 1:
Error: Required module `Graphics' is unavailable

$ ocamlfind ocamlc -o a.exe a.ml -linkpkg -package graphics
$ ls a.exe
a.exe

```
