Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a specific version of ocaml compiler with opam

How can I install a specific version of ocaml compiler (and compatible packages) using opam (or another package manger)?

I took a quick look through the opam documentation, but I don't find a relevant information.

I need ocaml compiler (preferably the native code compiler) to build unison, a software for file synchronization. I need to build unison on two machines using the same version of ocaml, or otherwise unison emits an error and aborts its duty (yiiii!).

I tried building ocaml version 4.04.0 from a tar ball and then using it for building unison, but on one of the machine the build of unison failed with the error message,

make[1]: Entering directory '/home/norio/Downloads/unison/unison-2.48.4_expand/src'
ocamlc -o mkProjectInfo unix.cma str.cma mkProjectInfo.ml
File "mkProjectInfo.ml", line 1:
Error: Error while linking /home/norio/Downloads/unison/ocaml_for_unison/lib/ocaml/unix.cma(Unix):
The external function `unix_has_symlink' is not available
if [ -f `which etags` ]; then \
    etags *.mli */*.mli *.ml */*.ml */*.m *.c */*.c *.txt \
          ; fi 
make[1]: Leaving directory '/home/norio/Downloads/unison/unison-2.48.4_expand/src'

I don't want to set off for the quest of unix_has_symlink function and devote myself for the exploration of the swamp of library dependencies where many developers had fallen before the civilization came and package managers were invented.

Is there anything like, opam install ocamlc-4.04 and opam install all-packages?


Addendum

The error message about unix_has_symlink was observed on a machine running Linux Mint 18 Cinnamon 64 bit. Is this function a part of some unix/linux library, rather than ocaml package?

like image 660
norio Avatar asked Nov 30 '16 21:11

norio


1 Answers

To create a switch with a particular version of the compiler do

opam switch create <compiler-version>

(Note: for the old opam 1.x it was opam switch <compiler-version>)

E.g.,

opam switch create 4.07.0

Or, if you want to create a fresh new switch that uses the same compiler as some other switch, then the syntax is

opam switch create <name> <compiler-version>

E.g.,

opam switch create myproj 4.07.0

Note, that if <name> is a folder, then a local switch will be created, e.g., opam switch ./myproj 4.07.0 will create a switch directly in the myproj folder.

To start with a specific version, i.e., when you first install opam, just do

opam init --compiler=<version>

E.g.,

opam init --compiler=4.07.0

To list available versions do

opam switch 

To see even more, do

opam switch list-available

To install a variant of a compiler, e.g., a compiler with flambda or spacetime, use the following general syntax,

opam switch create <switch-name> ocaml-variants.<version>+options <options>...

E.g.,

opam switch create myswitch ocaml-variants.4.13.0+options ocaml-option-flambda

use opam search ocaml-options for the full list of available options. It is possible to specify several options, e.g.,

opam switch create myswitch ocaml-variants.4.13.0+options ocaml-option-flambda ocaml-option-spacetime ocaml-option-static
like image 184
ivg Avatar answered Oct 27 '22 16:10

ivg