Creating opam switch version 5.3.0+trunk

I installed Ocaml on windows, and now I would like to create a new switch. In powershell I typed the following:

opam switch create ocaml-variants 5.3.0+trunk --jobs=1

Here is the output that I get:

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Switch invariant: ["ocaml-variants" {= "5.3.0+trunk"}]
[NOTE] It seems you have not updated your repositories for a while. Consider updating them with:
       opam update

[NOTE] External dependency handling not supported for OS family 'windows'.
       You can disable this check using 'opam option --global depext=false'

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
✢ installed base-bigarray.base
✢ installed base-threads.base
✢ installed base-unix.base
β–Ό retrieved ocaml-variants.5.3.0+trunk  (https://github.com/ocaml/ocaml/archive/trunk.tar.gz)
[ERROR] The compilation of ocaml-variants.5.3.0+trunk failed at "./configure --prefix=C:\\Users\\shuri\\AppData\\Local\\opam\\ocaml-variants
        --docdir=C:\\Users\\shuri\\AppData\\Local\\opam\\ocaml-variants\\doc/ocaml -C --disable-warn-error".

#=== ERROR while compiling ocaml-variants.5.3.0+trunk =========================#
# context     2.2.0~alpha0~20221228-r3 | win32/x86_64 |  | git+https://github.com/ocaml/opam-repository.git#6c3f73f42890cc19f81eb1dec8023c2cd7b8b5cd
# path        C:\Users\shuri\AppData\Local\opam\ocaml-variants\.opam-switch\build\ocaml-variants.5.3.0+trunk
# command     C:\Users\shuri\AppData\Local\opam\ocaml-variants\.opam-switch\build\ocaml-variants.5.3.0+trunk\./configure --prefix=C:\Users\shuri\AppData\Local\opam\ocaml-variants --docdir=C:\Users\shuri\AppData\Local\opam\ocaml-variants\doc/ocaml -C --disable-warn-error
# exit-code   69
# env-file    C:\Users\shuri\AppData\Local\opam\log\ocaml-variants-16204-0d7240.env
# output-file C:\Users\shuri\AppData\Local\opam\log\ocaml-variants-16204-0d7240.out
### output ###
# [...]
# checking whether stripping libraries is possible... no
# checking if libtool supports shared libraries... yes
# checking whether to build shared libraries... yes
# checking whether to build static libraries... yes
# checking how to run the C preprocessor... cl.exe -E
# checking C compiler vendor... msvc-1929
# checking whether host executables can be run in the build... yes
# checking whether #! works in shell scripts... yes
# checking whether the C compiler accepts -Wold-style-declaration... no
# checking whether the C compiler accepts -Wimplicit-fallthrough=5... no
# checking whether the C compiler accepts -Wimplicit-fallthrough... no
# configure: error: This version of MSVC is too old. Please use Visual Studio version 17.8 or above.



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
β”Œβ”€ The following actions failed
β”‚ Ξ» build ocaml-variants 5.3.0+trunk
└─
β”Œβ”€ The following changes have been performed (the rest was aborted)
β”‚ ✢ install base-bigarray base
β”‚ ✢ install base-threads  base
β”‚ ✢ install base-unix     base
└─
# Run eval $(opam env --switch=ocaml-variants) to update the current shell environment
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [y/n]

This is very confusing because I have the latest Visual Studio version. Do you have any idea how to fix it?

Just a wild guess, but maybe you have more than one MSVC version installed? The ./configure script detected the cl compiler, version 1929, which corresponds to Visual Studio 2019.

checking C compiler vendor… msvc-1929

Cheers,
Nicolas

Hi Nicolas,

That is most definitely the case. Following the ocaml installation page on windows, the first command you have to execute is

winget install Microsoft.VisualStudio.2019.BuildTools --override "--wait --passive --installPath C:\VS --addProductLang En-us --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"

I tried uninstalling the version above, however it causes all the Ocaml tooling to fail. I do not know how to tell my machine : β€œHey, I have a newer version of MSVC Build tools, please use that one from now on”

Try opam update first.
Do you have use opam 2.2 ?
I’m surprised opam wants to install a msvc port of ocaml.

ok, did the update. Here is my opam version : 2.2.0~alpha0~20221228-r3. However, when I try to create the switch I get exactly the same error message as above.

Your opam version is too old, try the official release for 2.2 opam - Platform Blog

1 Like

Thanks! I managed to update the opam version, but the new type of error appeared:

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><>  🐫
Switch invariant: ["ocaml-variants" {= "5.3.0+trunk"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
βˆ— installed base-bigarray.base
βˆ— installed base-threads.base
βˆ— installed base-unix.base
⬇ retrieved ocaml-variants.5.3.0+trunk  (https://github.com/ocaml/ocaml/archive/trunk.tar.gz)
[ERROR] The compilation of ocaml-variants.5.3.0+trunk failed at "./configure
        --prefix=C:\\Users\\shuri\\AppData\\Local\\opam\\ocaml_53
        --docdir=C:\\Users\\shuri\\AppData\\Local\\opam\\ocaml_53\\doc/ocaml -C --disable-warn-error".

#=== ERROR while compiling ocaml-variants.5.3.0+trunk =========================#
# context     2.2.0 | win32/x86_64 |  | git+https://github.com/ocaml/opam-repository.git#6c3f73f42890cc19f81eb1dec8023c2cd7b8b5cd
# path        ~\AppData\Local\opam\ocaml_53\.opam-switch\build\ocaml-variants.5.3.0+trunk
# command     ~\AppData\Local\opam\ocaml_53\.opam-switch\build\ocaml-variants.5.3.0+trunk\./configure --prefix=C:\Users\shuri\AppData\Local\opam\ocaml_53 --docdir=C:\Users\shuri\AppData\Local\opam\ocaml_53\doc/ocaml -C --disable-warn-error
# exit-code   77
# env-file    ~\AppData\Local\opam\log\ocaml-variants-21428-d6864e.env
# output-file ~\AppData\Local\opam\log\ocaml-variants-21428-d6864e.out
### output ###
# [...]
# checking for csc... csc
# configure: WARNING: Mono is not yet supported - C sharp tests disabled
# checking for ld... no
# checking for link... link
# checking how to print strings... printf
# checking for gcc... no
# checking for cc... no
# checking for cl.exe... cl.exe
# checking whether the C compiler works... no
# configure: error: in `/cygdrive/c/Users/shuri/AppData/Local/opam/ocaml_53/.opam-switch/build/ocaml-variants.5.3.0+trunk':
# configure: error: C compiler cannot create executables
# See `config.log' for more details



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
β”Œβ”€ The following actions failed
β”‚ Ξ» build ocaml-variants 5.3.0+trunk
└─
β”Œβ”€ The following changes have been performed (the rest was aborted)
β”‚ βˆ— install base-bigarray base
β”‚ βˆ— install base-threads  base
β”‚ βˆ— install base-unix     base
└─
# Run (& opam env --switch=ocaml_53) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ } to update the current
shell environment
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [y/n]

Would you kindly help me investigating this error a bit further?

It still doesn’t look like your opam repository is up to date.
Maybe paste the entire output of
opam --version + opam update + the opam switch creation

I removed the default switch, and now there is another type of error. Here are some examples of input/output:

input: opam --version
output: 2.2.0
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
input:

opam update

output:

<><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><>  🐫
[default] no changes from git+https://github.com/ocaml/opam-repository.git#6c3f73f42890cc19f81eb1dec8023c2cd7b8b5cd

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
input:

opam switch create ocaml_53 5.3.0+trunk

output:

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><>  🐫
Switch invariant: ["ocaml-variants" {= "5.3.0+trunk"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
[ERROR] Failed to get sources of ocaml-variants.5.3.0+trunk: Download failed
βˆ— installed base-bigarray.base
βˆ— installed base-threads.base
βˆ— installed base-unix.base

#=== ERROR while fetching sources for ocaml-variants.5.3.0+trunk ==============#
OpamSolution.Fetch_fail("https://github.com/ocaml/ocaml/archive/trunk.tar.gz (download failed)")


<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
β”Œβ”€ The following actions failed
β”‚ ⬇ fetch ocaml-variants 5.3.0+trunk
└─
β”Œβ”€ The following changes have been performed (the rest was aborted)
β”‚ βˆ— install base-bigarray base
β”‚ βˆ— install base-threads  base
β”‚ βˆ— install base-unix     base
└─
# Run (& opam env --switch=ocaml_53) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ } to update the current
shell environment
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [y/n]

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
input:

opam switch create ocaml_511 5.1.1 --jobs=1

output:

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><>  🐫
Switch invariant: ["ocaml-base-compiler" {= "5.1.1"} | "ocaml-system" {= "5.1.1"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
βˆ— installed base-bigarray.base
βˆ— installed base-threads.base
βˆ— installed base-unix.base
βˆ— installed ocaml-options-vanilla.1
⬇ retrieved ocaml-base-compiler.5.1.1  (cached)
[ERROR] The compilation of ocaml-base-compiler.5.1.1 failed at "./configure
        --prefix=C:\\Users\\shuri\\AppData\\Local\\opam\\ocaml_511
        --docdir=C:\\Users\\shuri\\AppData\\Local\\opam\\ocaml_511\\doc/ocaml -C".

#=== ERROR while compiling ocaml-base-compiler.5.1.1 ==========================#
# context     2.2.0 | win32/x86_64 |  | git+https://github.com/ocaml/opam-repository.git#6c3f73f42890cc19f81eb1dec8023c2cd7b8b5cd
# path        ~\AppData\Local\opam\ocaml_511\.opam-switch\build\ocaml-base-compiler.5.1.1
# command     ~\AppData\Local\opam\ocaml_511\.opam-switch\build\ocaml-base-compiler.5.1.1\./configure --prefix=C:\Users\shuri\AppData\Local\opam\ocaml_511 --docdir=C:\Users\shuri\AppData\Local\opam\ocaml_511\doc/ocaml -C
# exit-code   1
# env-file    ~\AppData\Local\opam\log\ocaml-base-compiler-22688-235621.env
# output-file ~\AppData\Local\opam\log\ocaml-base-compiler-22688-235621.out
### output ###
# [...]
# checking host system type... x86_64-pc-cygwin
# checking target system type... x86_64-pc-cygwin
# checking for ld... no
# checking for link... link
# checking how to print strings... printf
# checking for gcc... no
# checking for cc... no
# checking for cl.exe... no
# checking for clang... no
# configure: error: in `/cygdrive/c/Users/shuri/AppData/Local/opam/ocaml_511/.opam-switch/build/ocaml-base-compiler.5.1.1':
# configure: error: no acceptable C compiler found in $PATH
# See `config.log' for more details



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
β”Œβ”€ The following actions failed
β”‚ Ξ» build ocaml-base-compiler 5.1.1
└─
β”Œβ”€ The following changes have been performed (the rest was aborted)
β”‚ βˆ— install base-bigarray         base
β”‚ βˆ— install base-threads          base
β”‚ βˆ— install base-unix             base
β”‚ βˆ— install ocaml-options-vanilla 1
└─
# Run (& opam env --switch=ocaml_511) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ } to update the current
shell environment
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [y/n]

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
input:

opam switch create 4.14.2

output:

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><>  🐫
Switch invariant: ["ocaml-base-compiler" {= "4.14.2"} | "ocaml-system" {= "4.14.2"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
βˆ— installed base-bigarray.base
βˆ— installed base-threads.base
βˆ— installed base-unix.base
[ERROR] The compilation of ocaml-system.4.14.2 failed at "ocaml gen_ocaml_config.ml".

#=== ERROR while compiling ocaml-system.4.14.2 ================================#
# context     2.2.0 | win32/x86_64 |  | git+https://github.com/ocaml/opam-repository.git#6c3f73f42890cc19f81eb1dec8023c2cd7b8b5cd
# path        ~\AppData\Local\opam\4.14.2\.opam-switch\build\ocaml-system.4.14.2
# command     ~\AppData\Local\Programs\DKMLNA~1\usr\bin\ocaml.exe gen_ocaml_config.ml
# exit-code   2
# env-file    ~\AppData\Local\opam\log\ocaml-system-2328-86662a.env
# output-file ~\AppData\Local\opam\log\ocaml-system-2328-86662a.out
### output ###
# Exception:
# Sys_error
#  "C:\\Users\\shuri\\AppData\\Local\\Programs\\DKMLNA~1\\usr\\bin\\ocaml-realc.exe: No such file or directory".



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
β”Œβ”€ The following actions failed
β”‚ Ξ» build ocaml-system 4.14.2
└─
β”Œβ”€ The following changes have been performed (the rest was aborted)
β”‚ βˆ— install base-bigarray base
β”‚ βˆ— install base-threads  base
β”‚ βˆ— install base-unix     base
└─
# Run (& opam env --switch=4.14.2) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ } to update the current shell
environment
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [y/n]

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
input:

dkml version

output:

2.1.1

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

input:

dkml init --system

output:

dkml: FATAL: opam: no such command in "C:\Users\shuri\AppData\Local\Programs\DKMLNA~1\bin"

Perhaps the best course of action would be to remove completely ocaml from my machine.

After re-installing everything:

opam --version
2.2.0
opam update
<><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><>  🐫
[diskuv-2.1.1] no changes from git+https://github.com/diskuv/diskuv-opam-repository.git#2.1.1
[default] no changes from git+https://github.com/ocaml/opam-repository.git#6c3f73f42890cc19f81eb1dec8023c2cd7b8b5cd
opam switch create ocaml_53 5.3.0+trunk
<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><>  🐫
Switch invariant: ["ocaml-variants" {= "5.3.0+trunk"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
βˆ— installed base-bigarray.base
βˆ— installed base-threads.base
βˆ— installed base-unix.base
⬇ retrieved ocaml-variants.5.3.0+trunk  (https://github.com/ocaml/ocaml/archive/trunk.tar.gz)
[ERROR] The compilation of ocaml-variants.5.3.0+trunk failed at "./configure
        --prefix=C:\\Users\\shuri\\AppData\\Local\\opam\\ocaml_53
        --docdir=C:\\Users\\shuri\\AppData\\Local\\opam\\ocaml_53\\doc/ocaml -C --disable-warn-error".

#=== ERROR while compiling ocaml-variants.5.3.0+trunk =========================#
# context     2.2.0 | win32/x86_64 |  | git+https://github.com/ocaml/opam-repository.git#6c3f73f42890cc19f81eb1dec8023c2cd7b8b5cd
# path        C:\Users\shuri\AppData\Local\opam\ocaml_53\.opam-switch\build\ocaml-variants.5.3.0+trunk
# command     C:\Users\shuri\AppData\Local\opam\ocaml_53\.opam-switch\build\ocaml-variants.5.3.0+trunk\./configure --prefix=C:\Users\shuri\AppData\Local\opam\ocaml_53 --docdir=C:\Users\shuri\AppData\Local\opam\ocaml_53\doc/ocaml -C --disable-warn-error
# exit-code   69
# env-file    C:\Users\shuri\AppData\Local\opam\log\ocaml-variants-17460-ed2a89.env
# output-file C:\Users\shuri\AppData\Local\opam\log\ocaml-variants-17460-ed2a89.out
### output ###
# [...]
# checking whether stripping libraries is possible... no
# checking if libtool supports shared libraries... yes
# checking whether to build shared libraries... yes
# checking whether to build static libraries... yes
# checking how to run the C preprocessor... cl.exe -E
# checking C compiler vendor... msvc-1929
# checking whether host executables can be run in the build... yes
# checking whether #! works in shell scripts... yes
# checking whether the C compiler accepts -Wold-style-declaration... no
# checking whether the C compiler accepts -Wimplicit-fallthrough=5... no
# checking whether the C compiler accepts -Wimplicit-fallthrough... no
# configure: error: This version of MSVC is too old. Please use Visual Studio version 17.8 or above.



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
β”Œβ”€ The following actions failed
β”‚ Ξ» build ocaml-variants 5.3.0+trunk
└─
β”Œβ”€ The following changes have been performed (the rest was aborted)
β”‚ βˆ— install base-bigarray base
β”‚ βˆ— install base-threads  base
β”‚ βˆ— install base-unix     base
└─
# Run (& opam env --switch=ocaml_53) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ } to update the current
shell environment
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [y/n]

These threads are hard to follow for me since it is unclear what set of instructions you are following. Is there a webpage that is telling you to install 5.3.0+trunk or 5.1.1 on Windows (please link), or you doing that because you just want to explore what works / doesn’t work on Windows?

(I’m expecting most people to be following https://ocaml.org/docs/installing-ocaml, but that doesn’t mention the commands you are running.)

The chaotic nature of these recent posts reflects my confusion about the process. I do not know if there is a page for windows specifically that explains how to set up a switch with Ocaml version > 5.0.0. Let me make a small recap:

  1. installed Ocaml on windows the usual way, meaning the dkml distribution that you mentioned in the link above
  2. realised that I was not able to create a switch
  3. now I am trying to figure out how to get the desired switch. I suspect that my problem has something to do with opam.exe

Just to be clear I have Ocaml 4.14.2, with all the tooling and everything appears to be working, although I had to re-install it. I would like to know if I could set up a switch with the latest version to start a new experimentation phase. Feel free to ask me more questions if you would like to help me with that.

Actually, is it even possible to get the latest(5.2.0) Ocaml version on Windows?

DkML supports OCaml 4.14.2 (check the release notes of the latest release).

For OCaml 5+ on Windows you can try installing the new opam version: opam - Platform Blog

However be warned that the DkML distribution and the standard opam distribution may conflict with each other. You would be recommended to stick with one or the other unless you really know what you are doing.

To add onto @yawaramin’s answer, you can completely remove DkML including the opam root and global switches with Problem with platform tools installation - #2 by jbeckford.

I don’t believe 5.1.1 works with (EDIT:) Windows MSVC, and I’m unsure about trunk (but that should work).

2 Likes

On Windows, only the MinGW-w64 port is supported in OCaml 5.0 and the Cygwin port is restored in 5.1. Currently 5.3+trunk supports MSVC and clang-cl. OCaml needs at least Visual Studio 2022 version 17.8 (_MSC_VER = 1938), but you’re using Visual Studio 2019 version 16.10, 16.11 (_MSC_VER = 1929). If you want to use OCaml 5.3+trunk on Windows with MSVC, I suggest you update to the latest Visual Studio 2022. If you want to use OCaml 4.14, everything should work correctly, but I still suggest you switch to VS2022.

Actually, I have VS2022, but the command

winget install Microsoft.VisualStudio.2019.BuildTools --override "--wait --passive --installPath C:\VS --addProductLang En-us --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"

installs Visual Studio Build Tools 2019, and somehow the newer version(17.11.0) is not detected. It appears that I have now several MSVC versions.

That command is the first step in installing OCaml for windows. If I remove Visual Studio Build Tools 2019, everything breaks.

Do you know how to switch to the latest MSVC version?

What’s probably happening is that the VS 2022 doesn’t have the required tools (C compiler, Windows SDK, etc.) so it’s being ignored. If you’re installing Visual Studio using the graphical installer, ensure you have at least β€œMSVC v143 - VS 2022 C++ x64/x86 build tools (Latest)”, β€œWindows 11 SDK (10.0.22621.0)” and β€œC++/CLI support for v143 build tools (Latest)” selected.

You should also just be able to add VS 2022 build tools with:

winget install Microsoft.VisualStudio.2022.BuildTools --override "--add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --passive"

It’s also possible to run msvs-detect directly to see what it’s detecting, but that’s not as easy as it should be in opam (clone GitHub - metastack/msvs-tools: Microsoft Visual Studio Helper Scripts (OCaml) and run ./msvs-detect --all from with a Cygwin/MSYS2 bash prompt and it will indicate which versions are valid). I’ve opened Getting correct Visual Studio 2022 for OCaml 5.3+ Β· Issue #7 Β· ocaml-windows/papercuts Β· GitHub.

1 Like

Just for the casual Googler finding the thread:

  • The mingw-w64 port has always worked. i.e. mingw-w64 OCaml is fine in all versions of OCaml 4.x and 5.x in both 32 and 64-bit versions, with the standard OCaml 5.x caveat that 32-bit is bytecode-only.
  • The Cygwin port of OCaml is very rarely what anyone actually wants on Windows - it was not available in OCaml 5.0.0, but was restored in OCaml 5.1.0 (in 64-bit only - with full native code support - because 32-bit Cygwin is unsupported upstream).
  • The MSVC port of OCaml will be restored in OCaml 5.3.0 (32-bit and 64-bit with native code support), but is not available in OCaml 5.0.0 or OCaml 5.1.x. It is available in opam-repository for OCaml 5.2.0 with opam switch create 5.2.0-msvc ocaml-variants.5.2.0+msvc but, as found here, a working installation of Visual Studio 2022 must be available for it. OCaml 4.x works with any version of Visual Studio (as long as you can install it!)

I ran that command and it told me that the package has been installed and after attempting to update, no new version has been found

What do you mean by this?