How to install a specific version of ocaml compiler with opam
Asked Answered
R

1

17

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?

Reprehension answered 30/11, 2016 at 21:12 Comment(6)
Do you mind if I ask for details about the OS on the machine that you are getting this error? I think that unix_has_symlink is a pretty standard Unix thing.Asoka
@MikePierce Thanks for your comment. I added the information in the original post.Reprehension
This is a terrible solution, but it looks like the otherlib that is calling unix_has_symlink is new and was not in older versions of OCaml (not OCaml 4.01.0). So you could install an old version if this doesn't get resolved. :/Asoka
opam init --compiler=4.04.0 should install OCaml 4.04.0 for you.Redford
did you try: opam switch create 4.06.0? Should switch and install all at once.Pahang
I want compiler ocaml-variants.4.07.1+flambda but it doesn't show up: [ERROR] No compiler matching ocaml-variants.4.07.1+flambda' found, use opam switch list-available' to see what is available, or use --packages' to select packages explicitly.` but I've installed it before. What is going on?Pahang
P
32

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
Phipps answered 1/12, 2016 at 1:27 Comment(4)
if you don't have the version you want opam switch create 4.06.0 worked great for mePahang
yep, opam has changed its interface since that time, so I have updated the post, to reflect the newest interfacePhipps
As a note it took me a while to realize that after these, I also needed to run eval $(opam env).Vested
I want compiler ocaml-variants.4.07.1+flambda but it doesn't show up: [ERROR] No compiler matching ocaml-variants.4.07.1+flambda' found, use opam switch list-available' to see what is available, or use --packages' to select packages explicitly.` but I've installed it before. What is going on?Pahang

© 2022 - 2024 — McMap. All rights reserved.