When following install instructions for windows topkg and ocp-indent fail to compile

Hello, I’ve been trying to follow the installation instructions at Installing OCaml · OCaml Documentation using MinGW through MSYS2, and almost everything compiles except topkg and ocp-indent. the log when I try to install topkg and ocp-indent through opam reads

does anyone know what’s wrong?

I forgot to mention that ocamlfind is installed.

topkg should work if you do opam pin add ocamlfind git+https://github.com/dra27/ocamlfind.git#win-fixes and try again (this pulls in Windows build fixes (MSYS2, Cygwin, etc.) by dra27 · Pull Request #112 · ocaml/ocamlfind · GitHub which needs merging and releasing). I’m not sure that that will help the ocp-indent error, though.

The ocp-indent error is strange. The last lines of the output relate to a warning that is explicitly declared as not an error, so it shouldn’t have prevented the build from succeeding. It might be helpful to show the whole contents of output-file, as maybe the actual error can be found there.

Here’s the log, the actual error appears to be the same as the error for topkg

File “src/ocp-indent-dynlink/dune”, line 5, characters 12-19:
5 | (libraries findlib dynlink ocp-indent.lexer ocp-indent.utils))
^^^^^^^
Error: Library “findlib” not found.
→ required by library “ocp-indent.dynlink” in
_build/default/src/ocp-indent-dynlink
→ required by executable indentMain in src/ocp-indent/dune:9
→ required by _build/default/src/ocp-indent/indentMain.exe
→ required by _build/install/default/bin/ocp-indent.exe
→ required by _build/default/ocp-indent.install
→ required by alias install
(cd build/default && C:\Users\willf\AppData\Local\opam\default\bin\ocamlc.opt.exe -w -40 -w -9 -warn-error -57 -g -bin-annot -I src/ocp-indent-lib/.ocp_indent_lib.objs/byte -I src/ocp-indent-lexer/.ocp_indent_lexer.objs/byte -I src/ocp-indent-utils/.ocp_indent_utils.objs/byte -intf-suffix .ml -no-alias-deps -o src/ocp-indent-lib/.ocp_indent_lib.objs/byte/indentBlock.cmo -c -impl src/ocp-indent-lib/indentBlock.ml)
File “src/ocp-indent-lib/indentBlock.ml”, lines 1698-1700, characters 4-13:
1698 | …{kind=KExpr i}::p,
1699 | ({token=EOF} :: tok :: _ (* spurious warning 57 here *)
1700 | | tok::
)
Warning 57 [ambiguous-var-in-pattern-guard]: Ambiguous or-pattern variables under guard;
variable tok appears in different places in different or-pattern alternatives.
Only the first match will be used to evaluate the guard expression.
(See manual section 11.5)
(cd build/default && C:\Users\willf\AppData\Local\opam\default\bin\ocamlopt.opt.exe -w -40 -w -9 -warn-error -57 -g -I src/ocp-indent-lib/.ocp_indent_lib.objs/byte -I src/ocp-indent-lib/.ocp_indent_lib.objs/native -I src/ocp-indent-lexer/.ocp_indent_lexer.objs/byte -I src/ocp-indent-lexer/.ocp_indent_lexer.objs/native -I src/ocp-indent-utils/.ocp_indent_utils.objs/byte -I src/ocp-indent-utils/.ocp_indent_utils.objs/native -intf-suffix .ml -no-alias-deps -o src/ocp-indent-lib/.ocp_indent_lib.objs/native/indentBlock.cmx -c -impl src/ocp-indent-lib/indentBlock.ml)
File “src/ocp-indent-lib/indentBlock.ml”, lines 1698-1700, characters 4-13:
1698 | …{kind=KExpr i}::p,
1699 | ({token=EOF} :: tok :: _ (* spurious warning 57 here *)
1700 | | tok::
)
Warning 57 [ambiguous-var-in-pattern-guard]: Ambiguous or-pattern variables under guard;
variable tok appears in different places in different or-pattern alternatives.
Only the first match will be used to evaluate the guard expression.
(See manual section 11.5)

Trying this. Thanks!

Seeing the full log: yes, that should also fix the ocp-indent failure

still seems to be failing with the same error

I should have more closely noticed the OCaml version (4.14.2) and the opam-repository sha (ee3428377 - so including ocaml/opam-repository#28897)! I’m struggling to reproduce this - what’s the output from opam list and opam pin at the moment in your switch?

opam list returns

PS C:\\Users\\willf> opam list

# Packages matching: installed

# Name                    # Installed    # Synopsis

arch-x86_64               1              Build OCaml for amd64 (64-bit)
base                      v0.16.4        Full standard library replacement for OCaml
base-bigarray             base
base-bytes                base           Bytes library distributed with the OCaml compiler
base-threads              base
base-unix                 base
camlp-streams             5.0.1          The Stream and Genlex libraries for use with Camlp4 and Camlp5
chrome-trace              3.20.2         Chrome trace event generation library
cmdliner                  2.0.0          Declarative definition of command line interfaces for OCaml
conf-mingw-w64-gcc-x86_64 1              Virtual package for GCC on x86_64 mingw-w64 (64-bit x86_64)
cppo                      1.8.0          Code preprocessor like cpp for OCaml
csexp                     1.5.2          Parsing and printing of S-expressions in Canonical form
dune                      3.20.2         Fast, portable, and opinionated build system
dune-build-info           3.20.2         Embed build information inside executable
dune-configurator         3.20.2         Helper library for gathering system configuration
dune-rpc                  3.20.2         Communicate with dune using rpc
dyn                       3.20.2         Dynamic type
either                    1.0.0          Compatibility Either module
fiber                     3.7.0          Dune’s monadic structured concurrency library
fix                       20250919       Algorithmic building blocks for memoization, recursion, and more
flexdll                   0.44           FlexDLL Sources
host-arch-x86_64          1              OCaml on amd64 (64-bit)
host-system-mingw         1              OCaml for mingw-w64
jsonrpc                   1.21.0-4.14    Jsonrpc protocol implemenation
lwt                       5.9.2          Promises and event-driven I/O
menhir                    20250912       An LR(1) parser generator
menhirCST                 20250912       Runtime support library for unparsers generated by Menhir
menhirLib                 20250912       Runtime support library for parsers generated by Menhir
menhirSdk                 20250912       Compile-time library for auxiliary tools related to Menhir
merlin-lib                4.19-414       Merlin’s libraries
mew                       0.1.0          Modal editing witch
msvs-detect               0.7.0          Microsoft Visual Studio environment settings detection script
msys2                     0.1.0          MSYS2 Environment Settings
msys2-mingw64             1              MSYS2 MINGW64 Environment
ocaml                     4.14.2         The OCaml compiler (virtual package)
ocaml-config              3              OCaml Switch Configuration
ocaml-env-mingw64         1              GCC mingw-w64 OCaml Runtime Dependency (64-bit)
ocaml-options-vanilla     1              Ensure that OCaml is compiled with no special options enabled
ocaml-variants            4.14.2+options Official release of OCaml 4.14.2
ocaml-version             4.0.3          Manipulate, parse and generate OCaml compiler version strings
ocamlbuild                0.16.1         OCamlbuild is a build system with builtin rules to easily build most OCaml proj
ocamlc-loc                3.20.2         Parse ocaml compiler output into structured form
ocamlfind                 1.9.8.git      pinned to version 1.9.8.git at git+https://github.com/dra27/ocamlfind.git#win-f
ocamlformat-rpc-lib       0.28.1         Auto-formatter for OCaml code (RPC mode)
ocamlgraph                2.2.0          A generic graph library for OCaml
ocplib-endian             1.2            Optimised functions to read and write int16/32/64 from strings and bigarrays
opam-core                 2.1.6          Core library for opam 2.1
opam-file-format          2.2.0          Parser and printer for the opam file syntax
opam-format               2.1.6          Format library for opam 2.1
ordering                  3.20.2         Element ordering
pp                        2.0.0          Pretty-printing library
ppx_yojson_conv_lib       v0.16.0        Runtime lib for ppx_yojson_conv
re                        1.14.0         RE is a regular expression library for OCaml
result                    1.5            Compatibility Result module
seq                       base           Compatibility package for OCaml’s standard iterator type starting from 4.07.
sexplib0                  v0.16.0        Library containing the definition of S-expressions and some base converters
spawn                     v0.17.0        Spawning sub-processes
stdio                     v0.16.0        Standard IO library for OCaml
stdune                    3.20.2         Dune’s unstable standard library
system-mingw              1              Build OCaml for mingw-w64
trie                      1.0.0          Strict impure trie tree
uchar                     0.0.2          Compatibility library for OCaml’s Uchar module
winpthreads               20240209-1     Posix Threads for Windows (winpthreads) Sources
xdg                       3.20.2         XDG Base Directory Specification
yojson                    2.2.2          Yojson is an optimized parsing and printing library for the JSON format

and opam pin returns

ocamlfind.1.9.8.git    git  git+https://github.com/dra27/ocamlfind.git#win-fixes  (at
c9efeea72743b2ff59ef67d354e0a88a08804a2c)

I just installed through Winget as shown in the instructions

I’m very puzzled as to what the full series of steps is/was here. What’s additionally the output of opam option sys-pkg-manager-cmd and, if you don’t mind sharing it, what’s your PATH? (echo %PATH%).

What made you install MSYS2, though, or did you not knowingly do that?

opam sys-pkg-manager-cmd

returns []

and echo %PATH% returns

C:\Users\willf\AppData\Local\Programs\Python\Python314;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\java8path;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\NVIDIA Corporation\NVIDIA App\NvDLISR;C:\Program Files\BRL-CAD 7.42.0\bin;C:\Users\willf\AppData\Local\Muse Hub\lib;C:\Program Files\OpenSSL-Win64\bin;C:\Program Files\Neovim\bin;C:\Program Files\Steel Bank Common Lisp;C:\Program Files\Cabbage;C:\Program Files\CMake\bin;C:\Program Files\gsudo\Current;C:\Program Files\Csound6_x64\bin;C:\Program Files\PowerShell\7;C:\Program Files\Wolfram Research\WolframScript;C:\msys64\usr\bin;C:\msys64\mingw64\bin;C:\msys64\ucrt64\bin;C:\msys64\clang64\bin;C:\Users\willf\Downloads\jdt-language-server-1.52.0-202510301627\bin;F:\Strawberry\c\bin;F:\Strawberry\perl\site\bin;F:\Strawberry\perl\bin;C:\FPC\3.2.2\bin\i386-Win32;F:\gradle-9.2.0-bin\gradle-9.2.0\bin;C:\Program Files\Git\cmd;C:\Users\willf\AppData\Local\Programs\Python\Python314\Scripts;C:\Users\willf\AppData\Local\Programs\Python\Python314;C:\Program Files\OpenSSL-Win64\bin;C:\Users\willf\AppData\Local\Microsoft\WindowsApps;C:\Users\willf\AppData\Local\Programs\MiKTeX\miktex\bin\x64;C:\Users\willf\AppData\Local\Microsoft\WinGet\Packages\Gyan.FFmpeg_Microsoft.Winget.Source_8wekyb3d8bbwe\ffmpeg-7.1.1-full_build\bin;C:\Users\willf\AppData\Local\Microsoft\WinGet\Packages\yt-dlp.FFmpeg_Microsoft.Winget.Source_8wekyb3d8bbwe\ffmpeg-N-120858-gae448e00af-win64-gpl/bin;C:\Users\willf\AppData\Local\Microsoft\WinGet\Packages\yt-dlp.yt-dlp_Microsoft.Winget.Source_8wekyb3d8bbwe;C:\Users\willf\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\willf\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\pip;C:\Users\willf\AppData\Local\Microsoft\WinGet\Links;C:\ghcup\bin;C:\Users\willf\Downloads\jdt-language-server-1.52.0-202510301627\bin;C:\Users\willf\AppData\Local\Coursier\data\bin;F:\FreeBASIC-1.10.1-winlibs-gcc-9.3.0\FreeBASIC-1.10.1-winlibs-gcc-9.3.0 `

and I installed MSYS2 because I already had it set up.

Excellent, thanks - I’ve reproduced it, so hopefully on to the smaller matter of fixing it…!

Right, got it: if you still have my win-fixes branch pinned, opam upgrade ocamlfind should fix it (it will pull an updated part). As it happens, downgrading to ocamlfind 1.9.5 should also work.

All that said, the fundamental problem is that your shell is misconfigured.

Did you put C:\msys64\usr\bin etc. into PATH yourself, or did an installer do it? It needs to appear before C:\WINDOWS\system32 (if you didn’t configure this yourself and it was done by an installer, that’d be useful to know, because opam should mitigate this, but I wasn’t aware that any of the MSYS2 installers ever set-up PATH in this way).

The background, as it happens, is one of the “improvements” in https://github.com/ocaml/ocamlfind/pull/73 introduced a dependency on find, and because you’ve got MSYS2’s C:\msys64\usr\bin after C:\WINDOWS\system32 the script is trying to use the Windows find command, which doesn’t work - this specifically causes ocamlfind’s configure script not to generate the META file for the findlib package (that’s it’s own library) which means that the topfind script doesn’t work, and all the other failures stem from that.

1 Like

thank you I adjusted it’s position in PATH

Had you set up your PATH originally, or had another tool done so?