Compile issues trying to install dune, ocamlfind, etc

The compiler install and opam switch seemed to work fine, , but the opam install of dune, utop, etc. is having issues (see below)

$ opam switch create . ocaml-variants.4.09.0+msvc64c

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ocaml-variants.4.09.0+msvc64c] downloaded from https://dl.bintray.com/fdopen/prebuild-win32-ocaml-packages/4.09.0+msvc64c.tar.xz

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
∗ installed base-bigarray.base
∗ installed base-threads.base]
∗ installed base-unix.basesed]
∗ installed ocaml-variants.4.09.0+msvc64cl.sh]
∗ installed ocaml-config.1
∗ installed ocaml.4.09.0.09.0]
Done.


<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
∗ installed seq.basemake all] [conf-m4: sh echo | m4] [dune: ocaml bootstrap.ml] [ocamlbuild: patch]
[ERROR] The compilation of dune failed at "D:\\crime\\dune\\_opam\\bin\\ocaml.exe bootstrap.ml -j 11". bootstrap.ml] [ocamlbuild: make configure.make]
∗ installed conf-m4.1
[ERROR] The compilation of cmdliner failed at "D:\\cygwin64\\bin\\make.exe all PREFIX=D:/crime/dune/_opam".h
[ERROR] The compilation of ocamlbuild failed at "D:\\cygwin64\\bin\\make.exe all".
[ERROR] The compilation of ocamlfind failed at "D:\\cygwin64\\bin\\make.exe opt".

#=== ERROR while compiling ocamlfind.1.8.1 ====================================#
# context     2.0.5 | win32/x86_64 | ocaml-variants.4.09.0+msvc64c | git+https://github.com/fdopen/opam-repository-mingw.git#opam2
# path        D:/crime/dune/_opam/.opam-switch/build/ocamlfind.1.8.1
# command     D:\cygwin64\bin\make.exe opt
# exit-code   2
# env-file    ~/.opam/log/ocamlfind-18980-eec089.env
# output-file ~/.opam/log/ocamlfind-18980-eec089.out
### output ###
# for p in findlib; do ( cd src/$p; /usr/bin/make opt ) || exit; done
# make[1]: Entering directory '/cygdrive/d/crime/dune/_opam/.opam-switch/build/ocamlfind.1.8.1/src/findlib'
# ocamlopt -I +compiler-libs -g -opaque -c findlib_config.ml
# 'ml64' is not recognized as an internal or external command,
# operable program or batch file.
# File "findlib_config.ml", line 1:
# Error: Assembler error, input left in file D:\cygwin64\tmp\camlasm20de40.asm
# make[1]: *** [Makefile:163: findlib_config.cmx] Error 2
# make[1]: Leaving directory '/cygdrive/d/crime/dune/_opam/.opam-switch/build/ocamlfind.1.8.1/src/findlib'
# make: *** [Makefile:17: opt] Error 2


#=== ERROR while compiling ocamlbuild.0.14.0 ==================================#
# context     2.0.5 | win32/x86_64 | ocaml-variants.4.09.0+msvc64c | git+https://github.com/fdopen/opam-repository-mingw.git#opam2
# path        D:/crime/dune/_opam/.opam-switch/build/ocamlbuild.0.14.0
# command     D:\cygwin64\bin\make.exe all
# exit-code   2
# env-file    ~/.opam/log/ocamlbuild-18980-8b47d2.env
# output-file ~/.opam/log/ocamlbuild-18980-8b47d2.out
### output ###
# [...]
# ocamlc.opt -w L -w R -w Z -I src -I +unix -safe-string -bin-annot -strict-sequence -c src/ocamlbuild_unix_plugin.mli
# ocamlc.opt -w L -w R -w Z -I src -I +unix -safe-string -bin-annot -strict-sequence -c src/ocamlbuild_unix_plugin.ml
# ocamlc.opt -w L -w R -w Z -I src -I +unix -safe-string -bin-annot -strict-sequence -c src/ocamlbuild.mli
# ocamlc.opt -w L -w R -w Z -I src -I +unix -safe-string -bin-annot -strict-sequence -c src/ocamlbuild.ml
# ocamlc.opt -I +unix -I src -o ocamlbuild.byte unix.cma src/ocamlbuild_pack.cmo src/ocamlbuild_plugin.cmo src/ocamlbuild_executor.cmo src/ocamlbuild_unix_plugin.cmo src/ocamlbuild.cmo
# ocamlc.opt -a -o src/ocamlbuildlib.cma src/ocamlbuild_pack.cmo src/ocamlbuild_plugin.cmo src/ocamlbuild_executor.cmo src/ocamlbuild_unix_plugin.cmo
# ocamlopt.opt -for-pack Ocamlbuild_pack -w L -w R -w Z -I src -I +unix -safe-string -bin-annot -strict-sequence -c src/const.ml
# 'ml64' is not recognized as an internal or external command,
# operable program or batch file.
# File "src/const.ml", line 1:
# Error: Assembler error, input left in file D:\cygwin64\tmp\camlasme26e2b.asm
# make: *** [Makefile:428: src/const.cmx] Error 2


#=== ERROR while compiling dune.2.1.2 =========================================#
# context     2.0.5 | win32/x86_64 | ocaml-variants.4.09.0+msvc64c | git+https://github.com/fdopen/opam-repository-mingw.git#opam2
# path        D:/crime/dune/_opam/.opam-switch/build/dune.2.1.2
# command     D:\crime\dune\_opam\bin\ocaml.exe bootstrap.ml -j 11
# exit-code   2
# env-file    ~/.opam/log/dune-18980-320155.env
# output-file ~/.opam/log/dune-18980-320155.out
### output ###
# ocamlc -custom -w -24 -g -o .duneboot.exe -I boot unix.cma boot/libs.ml boot/duneboot.ml
# 'cl' is not recognized as an internal or external command,
# operable program or batch file.
# ** Fatal error: Error while compiling
# File "boot/duneboot.ml", line 1:
# Error: Error while building custom runtime system


#=== ERROR while compiling cmdliner.1.0.4 =====================================#
# context     2.0.5 | win32/x86_64 | ocaml-variants.4.09.0+msvc64c | git+https://github.com/fdopen/opam-repository-mingw.git#opam2
# path        D:/crime/dune/_opam/.opam-switch/build/cmdliner.1.0.4
# command     D:\cygwin64\bin\make.exe all PREFIX=D:/crime/dune/_opam
# exit-code   2
# env-file    ~/.opam/log/cmdliner-18980-09b4f7.env
# output-file ~/.opam/log/cmdliner-18980-09b4f7.out
### output ###
# ocaml build.ml cma
# ocaml build.ml cmxa
# 'ml64' is not recognized as an internal or external command,
# operable program or batch file.
# File "cmdliner_trie.ml", line 1:
# Error: Assembler error, input left in file D:\cygwin64\tmp\camlasm4a8971.asm
# exited with 2: "ocamlopt.opt" "-g" "-bin-annot" "-safe-string" "cmdliner.mli" "cmdliner_base.mli" "cmdliner_manpage.mli" "cmdliner_suggest.mli" "cmdliner_trie.mli" "cmdliner_trie.ml" "cmdliner_suggest.ml" "cmdliner_info.mli" "cmdliner_docgen.mli" "cmdliner_cli
ne.mli" "cmdliner_base.ml" "cmdliner_manpage.ml" "cmdliner_msg.mli" "cmdliner_term.mli" "cmdliner_info.ml" "cmdliner_docgen.ml" "cmdlin[...]
# make: *** [Makefile:53: build-native] Error 1



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build cmdliner   1.0.4
│ λ build dune       2.1.2
│ λ build ocamlbuild 0.14.0
│ λ build ocamlfind  1.8.1
└─
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install conf-m4 1
│ ∗ install seq     base
└─

The former state can be restored with:
    D:\cygwin64\usr\local\bin\opam.exe switch import "D:/crime/dune/_opam/.opam-switch/backup/state-20200128155006.export"

It seems your C toolchain is not in your executable search path. Did you eval $(opam env) ?

If you want to use the msvc toolchain, you must install Visual Studio and configure your environment manually. See https://github.com/ocaml/ocaml/blob/trunk/README.win32.adoc#microsoft-visual-cc-ports for details.

Once Visual Studio is installed, you can try the following command inside a cygwin shell (see https://fdopen.github.io/opam-repository-mingw/ocaml-env/ )

eval $(ocaml-env cygwin)

The command tries to configure the environment for you. But the auto detection of msvc environment might not work any longer. I haven’t looked at it, after I’ve set it up for https://github.com/ocaml/ocaml-ci-scripts/ (that’s the purpose of the 4.09.0+msvc64c switch that you are trying to use). And now newer versions of Visual Studio are available…

1 Like

I would strongly recommend to use the mingw64 version of the compiler as opposed to msvc64. For mingw64 you don’t need Visual Studio, and all the setup pain associated with it. While msvc64 builds most pure-ocaml packages it has trouble with packages that have C dependencies, because many packages rely on GCC-specific extensions and flags. Since mingw64 is based on GCC, a larger subset of C-dependent packages will work out-of-the-box.

Plus, I am not aware of any advantages of msvc64 over mingw64.

Anyway, if you have to use msvc64, I am sure we can get you running too.

One way to set up the necessary environment variables for msvc64 is to launch Developer Command Prompt for Visual Studio:

https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs

It’s just a cmd prompt that has some environment variables set up, so you have the Visual C compiler (cl), linker (link), assembler (ml64) and the right system libraries.

You run this command prompt and from there you call c:/OCaml64/bin/bash.exe and that will give you a Cygwin shell with those variables set up.

I think this is one way that can solve your immediate errors, we can take it from there.

So let me try to explain what I am trying to do, and then tell you what I have tried based on the good advice above.

I would like to setup a dev environment for our team that consists of

  1. Win10 workstation (that is what I.T. will provide us)
  2. VSCode as the editor (tentatively with the reason-vscode plugin, but if any additional formatters, intellisense, or tools, we are open)
  3. Dune and OPAM scripts as NPM tasks (parallels what we do on the front end with ReasonML and BuckleScript)

So no, no reason for VS2019, (I have it installed, but I hear you about ming,

I am trying to follow the suggestions at: https://medium.com/@bobbypriambodo/starting-an-ocaml-app-project-using-dune-d4f74e291de8 But he is using Unix.

I would prefer not to use Cygwin, and be able to do OPAM and DUNE without it - since I don’t see how that integrates with VSCODE.

Now, in that Medium article he said: eval $(opam config env), but what I have done based on comments above are:

$ opam switch create . ocaml-variants.4.09.0+mingw64c -- no problem
$ eval $(opam env)
$ opam install merlin ocp-indent dune utop

all in cygwin (but as I said, I would like to avoid cygwin if possible)

The final result still is as error, but it is further along.

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[biniou.1.2.1] found in cache
[camomile.1.0.2] found in cache
[charInfo_width.1.1.0] found in cache
[cmdliner.1.0.4] found in cache
[cppo.1.6.6] found in cache
[dune.2.1.2] found in cache
[dune-configurator.2.1.2] found in cache
[dune-private-libs.2.1.2] found in cache
[easy-format.1.3.2] found in cache
[lambda-term.2.0.3] found in cache
[lwt.5.1.1] found in cache
[lwt_log.1.1.1] found in cache
[lwt_react.1.1.3] found in cache
[merlin.3.3.3] found in cache
[mmap.1.1.0] found in cache
[ocamlbuild.0.14.0] found in cache
[ocamlfind.1.8.1] found in cache
[ocp-indent.1.8.1] found in cache
[ocplib-endian.1.0] found in cache
[react.1.2.1] found in cache
[result.1.4] found in cache
[topkg.1.0.1] found in cache
[utop.2.4.3] found in cache
[yojson.1.7.0] found in cache
[zed.2.0.4] found in cache
[ERROR] The sources of the following couldn't be obtained, aborting:
          - dune-private-libs.2.1.2
          - ocamlfind.1.8.1

The error was due to Cygwin not handling http_proxy as HTTP_PROXY (a windows issue). Which is why I still want to get away from Cygwin.

My question still stands, about how to reach my goal of VSCODE, dune integration with no cygwin.

Which is why I still want to get away from Cygwin.

Have you already tried https://esy.sh/ ?
They at least don’t use cygwin’s curl for downloading the files…

My question still stands, about how to reach my goal of VSCODE, dune integration with no cygwin.

Convince the developers of OCaml, ocamlfind and many other programs and libraries to switch to a different build system. As long as this won’t happened, you can’t avoid cygwin (or wsl).

During your daily development, you don’t have to deal with the cygwin terminal. Start a cygwin shell once and run

mkshortcut -a '"C:/path/wherever/vscode/is/installed/Code.exe"' -D -n "Vscode-Link" /usr/local/bin/ocaml-env-win.exe

It will create a link called “Vscode-Link” on your Desktop. If you use this link to start VScode, your environment is properly set up for your current opam switch. You won’t notice any difference, if the gcc toolchain or the msvc toolchain is used internally (as long as your project doesn’t include c files).

with the vscode link, how do I run cygwin commands like $ dune build … (I.e. can I run them in Terminal as poweshell, or cmd commands?

also is it ocaml-env.exe or ocaml-env-win.exe ?

with the vscode link, how do I run cygwin commands like $ dune build … (I.e. can I run them in Terminal as poweshell, or cmd commands?

Yes, you can start a terminal (powershell or cmd) from within VsCode and manually type dune build ..... dune is a native windows program.

Just install https://marketplace.visualstudio.com/items?itemName=freebroccolo.reasonml from within VsCode in order to get syntax highlighting, type hints, etc.
I’m not familiar with the details, I only use emacs.

also is it ocaml-env.exe or ocaml-env-win.exe ?

It’s ocaml-env-win.exe. I’ve corrected it inside the post above.

In my case, the path to VSCODE is:

C:\Users\ysg4206\AppData\Local\Programs\Microsoft VS Code\Code.exe

Ah, one pair of extra quotes is probably necessary in case of spaces or similar chars - I’ve once again fixed the command:

mkshortcut -a '"C:\Users\ysg4206\AppData\Local\Programs\Microsoft VS Code\Code.exe"' -D -n "Vscode-Link" /usr/local/bin/ocaml-env-win.exe

Or just edit the link manually after it was created and properly quote the parameter that is passed to ocaml-env-win.exe…

One alternative to creating a link like @fdopen suggests, is to start VS Code from within a Cygwin shell. You can run code your_file.ml from the shell and VS Code will open with the correct environment set up.

The setup that I’ve used uses the Reason VS Code extension with the following settings:

{
  "terminal.integrated.shell.windows": "c:\\OCaml64\\bin\\bash.exe",
  "reason.path.ocamlmerlin": "ocamlmerlin-server"
}

This sets up Cygwin’s bash to be used as VS Code integrated shell, from where you can run utop or dune:

To my knowledge, there’s no way to get around either Cygwin or WSL on Windows to develop OCaml.

All of this is fascinating, and I really appreciate the info. I am going to go back and do some research with esy and then compare it to the dune build process.

Not clear where the symlink or the cygwin VSCODE terminal is better, I suspect the first supports npm run commands.

But in the final analysis if esy can build both reasonml and ocaml and I can get it to work: (see https://github.com/esy-ocaml/hello-reason/issues/62 ) then I inclined to esy.

1 Like