# "dunelongcmd" Linking Error on Windows using ocamlopt

**URL:** <https://discuss.ocaml.org/t/dunelongcmd-linking-error-on-windows-using-ocamlopt/15469>\
**Category:** Learning\
**Tags:** windows, linking, dune\
**Created:** [October 18, 2024, 6:34pm UTC](https://discuss.ocaml.org/t/dunelongcmd-linking-error-on-windows-using-ocamlopt/15469 "2024-10-18T18:34:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![b-valdez](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/b-valdez/32/5580_2.png) [@b-valdez](https://discuss.ocaml.org/u/b-valdez)\
**Post date:** [October 18, 2024, 6:34pm UTC](https://discuss.ocaml.org/t/dunelongcmd-linking-error-on-windows-using-ocamlopt/15469/1 "2024-10-18T18:34:42Z")

</div>

Hello everyone,  
Because Opam now supports Windows I have experimented with moving my Ocaml-Workspaces from WSL into Windows proper. This was successful and on my laptop there was a noticeable improvement to the startup time of Visual Studio Code, which no longer needs to connect to WSL.  
Since then I have added additional dependencies in order to try and benefit from parallelism. Now I am getting errors like this:

```PowerShell
PS D:\Workspaces\aoc\solutions\2023\1> dune runtest --display=short
Entering directory 'D:\Workspaces\aoc'
File "solutions/2023/1/dune", lines 1-7, characters 0-113:
1 | (library
2 | (name aoc_2023_1)
3 | (inline_tests)
4 | (preprocess
5 | (pps ppx_jane))
6 | (modes best)
7 | (libraries re aoc_std))
    ocamlopt solutions/2023/1/.aoc_2023_1.inline-tests/inline_test_runner_aoc_2023_1.exe (exit 2)
/bin/bash: D:TMPbuild_dc7e34_dunelongcmdb2df95: No such file or directory
** Fatal error: Error during linking

File "caml_startup", line 1:
Error: Error during linking (exit code 2)

```

There have been no changes to the files in the folder but the library aoc\_std now has the additional dependencies and an additional module.  
If I change `(modes best)` to `(modes byte)` (and therefore use `ocamlc` instead of `ocamlopt`) it works just fine.  
It seems that by adding the dependencies the (very, very long) `ocamlopt` invocation crossed some threshold which required creating some temporary file which when referred to had some issue with the Windows file separator.  
I am not quite sure whether this is a dune bug, an ocamlopt bug, a powershell bug or if I have something in my PATH which gets unexpectedly called instead of the cygwin equivalent.  
I am using the sandboxed (powershell) terminal from the Ocaml Platform extension out of Visual Code Studio. Opam uses its own cygwin installation. I use version 5.2.0 of ocaml and mingw-w64.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [October 18, 2024, 8:04pm UTC](https://discuss.ocaml.org/t/dunelongcmd-linking-error-on-windows-using-ocamlopt/15469/2 "2024-10-18T20:04:36Z")

</div>

It looks like something in your build called `/bin/bash` with a Windows-style path (containing backslashes). You may be able to find out what by looking at the Dune log, `_build/log`.

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![b-valdez](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/b-valdez/32/5580_2.png) [@b-valdez](https://discuss.ocaml.org/u/b-valdez)\
**Post date:** [October 19, 2024, 9:58am UTC](https://discuss.ocaml.org/t/dunelongcmd-linking-error-on-windows-using-ocamlopt/15469/3 "2024-10-19T09:58:31Z")

</div>

Thanks, that helped.  
I apparently have multiple bash.exe on my system and when I changed my PATH environment variable to prioritize the cygwin one, everything works just fine.  
The bash which produces the errors is in C:/Windows/System32 and is apparently using WSL.  
It is weird that dune logged “/bin/bash” when the used bash wasn’t in a folder called “bin”.

EDIT: No that wasn’t the problem. I added the following to my `dune-workspace` to remove the suspected problematic bash and use cygwins instead:

```dune
(context
 (default
  (paths
   (PATH
    (:standard \ "C:\\windows\\system32" "C:\\WINDOWS\\system32")
    "C:\\Users\\Benjamin\\.opam\\.cygwin\\root\\bin"))))

```

WIth `dune exec -- bash` I can see that the “right” bash is found, but I get still the same error. If I move the `"C:\\Users\\Benjamin\\.opam\\.cygwin\\root\\bin"` before standard everything works and I don’t have to remove from system32 from my PATH. So my problem is still solved, but I don’t know for sure what caused the problem in the first place.

---

<div class="post-metadata">

**Author:** ![jaycle](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jaycle/32/4161_2.png) [@jaycle](https://discuss.ocaml.org/u/jaycle)\
**Post date:** [November 28, 2024, 1:57am UTC](https://discuss.ocaml.org/t/dunelongcmd-linking-error-on-windows-using-ocamlopt/15469/4 "2024-11-28T01:57:41Z")

</div>

I hit this issue today. Added the .cygwin\root\bin to my path (at the top) which corrected it. However, it’d be nice if opam would use the correct bash that it installed. Where could we file an issue?

`dune init project`’s hello world works fine. But first time you link to a library, you’ll hit this, I think.

---

<div class="post-metadata">

**Author:** ![dra27](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dra27/32/5294_2.png) [@dra27](https://discuss.ocaml.org/u/dra27)\
**Post date:** [December 4, 2024, 7:52pm UTC](https://discuss.ocaml.org/t/dunelongcmd-linking-error-on-windows-using-ocamlopt/15469/5 "2024-12-04T19:52:06Z")

</div>

It is kind of a Dune bug (but Dune is in good company with the trick being used - the `flexlink` used by Windows OCaml has the same problem with long commands). The intent behind native Windows opam is that you’re actually using native Windows - so the expectation of `bash` is a flawed part of the legacy which expected the first thing a Windows OCaml user to do being the installation of a Unix environment (i.e. Cygwin) 🫣

opam 2.2 is only the start of sorting this out properly - what it has sorted is being able to _build and install_ packages from one of the two native Windows shells (that’s why the internal Cygwin installation is very intentionally not exposed by `opam env`) but there’s still more work to do (both in `opam` and other core platform tools) to be able to work on OCaml projects without hitting occasional Unixisms. The workaround from a native shell (cmd/PowerShell) in the meantime is either to install one’s own Cygwin/MSYS2 and use its bash or, as you’ve done, choosing to add the internal Cygwin’s `bin` directory to `PATH`. Note that this isn’t a silver bullet - if you’re using a Microsoft Visual Studio switch, for example, it’s very easy to end up breaking `ocamlopt`’s ability to call the linker.

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [February 23, 2025, 3:40pm UTC](https://discuss.ocaml.org/t/dunelongcmd-linking-error-on-windows-using-ocamlopt/15469/6 "2025-02-23T15:40:07Z")

</div>

Bumping this thread since there is still this problem for users who also have WSL installed, and this is still the solution.
