Graphics package?

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.

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.

Did you try the suggestions here? What do you get?

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.

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:

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!).

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

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).

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.

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 and running ./configure to see if it will build the graphics library.

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

=-=- Installing compiler 4.05.0 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[compiler.get] 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

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

#include <stdio.h>

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

?

1 Like

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

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 -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.

Progress - back with working OCaml! Now if you clone 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

Progress - I think…

I was not sure about 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

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.

did you run make after you ran ./configure?

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.

1 Like

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.

1 Like

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 ocaml1.cmo
File “none”, line 1:
Error: Required module `Graphics’ is unavailable

I chase on… Ian

@iru you need to explicitly link it.

a.ml:

let () = Graphics.open_graph "a"
$ 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
1 Like