Installing on Windows

Hi, I used to develop SML using SML/NJ and MLton long time ago and, after a long hiatus, wanted to refresh my functional programming skills with OCaml and its better ecosystem (in particular I’m interested in numerical programming with Owl).

I would like to use OCaml in Windows, not necessarily the latest multicore version, but at least one that has access to most libraries.

Unfortunately MSys2 only ships the interpreter and compiler in a broken format (no access to Stdlib no opam), and Diskuv fails to build with some error pertaining OCaml 4.14 and the C compiler. Is there any alternative which is not WSL2?

3 Likes

Personally, I am quite happy with the OCaml for Windows „distribution“. It is based on Cygwin, but compiles to native Windows. I am not sure whether it will support the new 5.0 version, but up to 4.14 it is up to date.
If you compile OpenBLAS and PLplot by yourself, you can also use the Owl framework on Windows. Respective instructions should be at the Owl GitHub repo: INSTALL_WINDOWS.md.

1 Like

That is a strange setup: cross-compiling to Mingw from Cygwin, when Msys2 is a perfectly functional environment that plays well with Mingw/UCRT/Clang compilers…

I think under the hood the difference between an MSYS and a Cygwin environment is not so big. Basically, MSYS is a stripped down Cygwin setup. In the past there had been issues to use the OCaml toolchain in MSYS, but that might be outdated.
An advantage of MSYS over Cygwin probably is, that some of the native Windows packages, e.g., for GTK3 are more uptodate there. On the Cygwin side there is the very nice “One-click” installer of the “OCaml for Windows” project. With respect to MinGW compilers there is not much difference between MSYS & Cygwin, IMHO.

1 Like

… an important info I forgot: The OCaml for Windows setup in Cygwin also uses the native MinGW compiler for Windows like MSYS. The question is, whether someone wants to call that “cross-compiling”…

After looking into which of the multiple gigabytes of Visual Studio I need to install, I decided to use WSL 2 (Windows Subsystem for Linux). It just works, seamlessly. Both file systems are visible on both sides, although very slow when used on the wrong system. Graphics (X11) works out of the box, although has poor resolution for me (I haven’t looked into improving that).

3 Likes

I have two types of development environment on our group boxes: mingw+Msys2 or MSVC, either running in Emacs or Visual Studio. I thus not mind the requirement to have them around, though I don’t understand why Diskuv insists on reinstalling it again.

Anyway, the WSL2 setup does work, but makes it rather more complicated if I think on sharing future projects with colleagues and students.

Is there any fundamental obstacle that prevents OCaml + opam becoming an ordinary package under Msys2 as it is on Linux? Just doing pacman -S opam and move on…

There is no obstacle except people power. Someone already did something like that for ocaml 4.14.0 (Search - MSYS2 Packages).

(I, for one, am uninterested in that approach because I don’t think it is wise to force Windows users to learn Unix (MSYS2). But if you or anybody else enjoy operating in a MSYS2 shell day-to-day, please go ahead and volunteer to be the MSYS2 package maintainer! Direct message me and perhaps I can point you in the right direction)

That a package “lives” in c:/msys64 does not mean that it requires at all a Unix-like environment. Indeed, the ocaml ports for MSYS2 are actually built using the Mingw compiler, which is completely native, linked to Microsoft’s libraries (either older ones, or modern UCRT).

The problem is that Ocaml’s inability to “relocate” properly has broken the port (See File "command line", line 1: Error: Unbound module Stdlib - OCaml version 4.11.1 · Issue #12854 · msys2/MINGW-packages · GitHub and remarks by the port maintainer). But I would argue that if this relocation problem is solved, and one ports also the opam infrastructure, this would be a more than suitable solution.

To be fair, I have the impression that Diskuv is already attempting this. The Diskuv installation procedure works by installing a copy of MSYS2 in some folder, and trying to build OCaml there. However, for some reason I don’t know, it does not work in my machine.

Yes, the relocation issue is a major problem, even more so for Windows. It is being worked on.

If Diskuv is not working on your machine, file a ticket at Issues · diskuv/dkml-installer-ocaml · GitHub. Since there is a major release coming out that supports OCaml 4.14 (it is being tested with students as we speak), you might want to wait a week or two.

3 Likes