Cannot install dune using opam on Window due to non-exist directory/file?
Hi everyone, I am trying to install dune using opam on Window 11. I come across this weird error
opam upgrade dune
dune is not installed. Install it? [y/n] y
The following actions will be performed:
=== install 1 package
β dune 3.17.2
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><> π«
β¬ retrieved dune.3.17.2 (https://opam.ocaml.org/cache)
[ERROR] The compilation of dune.3.17.2 failed at "ocaml boot/bootstrap.ml -j 15".
#=== ERROR while compiling dune.3.17.2 ========================================#
# context 2.3.0 | win32/x86_64 | ocaml.5.3.0 | https://opam.ocaml.org#69dc847b8315666c52c71b48a0952f9226e54067
# path ~\AppData\Local\opam\default\.opam-switch\build\dune.3.17.2
# command ~\AppData\Local\opam\default\bin\ocaml.exe boot/bootstrap.ml -j 15
# exit-code 2
# env-file ~\AppData\Local\opam\log\dune-37044-4ffb30.env
# output-file ~\AppData\Local\opam\log\dune-37044-4ffb30.out
### output ###
# [...]
# File "otherlibs/ocamlc-loc/src\\ocamlc_loc.mli", line 1, characters 4-9:
# Warning 53 [misplaced-attribute]: the "alert" attribute cannot appear in this context
# cd _boot && C:\Users\minh\AppData\Local\opam\default\bin\ocamlopt.opt.exe -c -g -no-alias-deps -w -49-6 -alert -unstable -I +unix -I +threads dune_action_plugin.mli
# File "otherlibs/dune-action-plugin/src\\dune_action_plugin.mli", line 1, characters 4-9:
# Warning 53 [misplaced-attribute]: the "alert" attribute cannot appear in this context
# cd _boot && C:\Users\minh\AppData\Local\opam\default\bin\ocamlopt.opt.exe -o ../_boot\dune.exe -g -I +unix -I +threads unix.cmxa threads.cmxa readdir.o wait4_stubs.o signal_stubs.o platform_stubs.o copyfile_stubs.o spawn_stubs.o dune_stats_stubs.o xdg_stubs.o dune_flock.o dune_digest_stubs.o csexp_rpc_stubs.o fsevents_stubs.o inotify_stubs.o fswatch_win_stubs.o sha512_stubs.o sha256_stubs.o s[...]
# /bin/bash: C:UsersminhAppDataLocalTemplongcmd33326e: No such file or directory
# ** Fatal error: Error during linking
#
# File "caml_startup", line 1:
# Error: Error during linking (exit code 2)
#
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><> π«
ββ The following actions failed
β Ξ» build dune 3.17.2
ββ
βΆβ No changes have been performed
It seems like there is a weird path due to concatenating. Also, I look at the directory C:/Users/Minh/AppData/Local/Temp, but I cannot find the longcmd33326e file. Is there any way to solve this? BTW, my opam version is 2.3.0 and my ocaml version is 5.3.0
/bin/bash: C:UsersminhAppDataLocalTemplongcmd33326e: No such file or directory
There is an issue with the path passed to the shell (it was not quoted properly). This is probably related to some aspect of your particular setup rather than a Dune issue (see eg https://discuss.ocaml.org/t/dunelongcmd-linking-error-on-windows-using-ocamlopt/15469).
You may want to post your issue in https://discuss.ocaml.org/ or even https://github.com/ocaml/opam/issues instead.
Hi @nojb, thank you for your suggestions, I have posted this issue in https://discuss.ocaml.org/. I also looked at the discuss dunlongcmd Although it seems a similar error, the problem is that the dune in the discuss has been installed successfully, while this is not the case for me.
I am also unable to bootstrap on windows. During the final step bash is being called. I don't have bash installed in PATH so the linking step fails. We also don't give a useful error message.
That invocation is not by the bootstrap script, but by the OCaml compiler. I think it's only being triggered because the linking command is long enough to require this extra indirection?
You could try working around this issue by renaming some of the stubs to avoid going over this threshhold. It's just a workaround, but it might be worth doing if it alleviates some pain for people.
The OCaml compiler should never call bash on Windows, except if you are using the Cygwin port (which is not recommended). Which port are you using?
I was following the instructions here: https://ocaml.org/install#windows
Which appear to be about the cygwin port...
Do you have a link for the other instructions?
Do you have a link for the other instructions?
As far as I know, these instructions are current, and OPAM should default to the mingw port (not cygwin). What do you get when you do ocamlc -config?
That looks fine to me.
version: 5.3.0
standard_library_default: C:/Users/a/AppData/Local/opam/default/lib/ocaml
standard_library: C:/Users/a/AppData/Local/opam/default/lib/ocaml
ccomp_type: cc
c_compiler: x86_64-w64-mingw32-gcc
bytecode_cflags: -O2 -fno-strict-aliasing -fwrapv -mms-bitfields
ocamlc_cflags: -O2 -fno-strict-aliasing -fwrapv -mms-bitfields
bytecode_cppflags:
ocamlc_cppflags:
native_cflags: -O2 -fno-strict-aliasing -fwrapv -mms-bitfields
ocamlopt_cflags: -O2 -fno-strict-aliasing -fwrapv -mms-bitfields
native_cppflags:
ocamlopt_cppflags:
bytecomp_c_compiler: x86_64-w64-mingw32-gcc -O2 -fno-strict-aliasing -fwrapv -mms-bitfields
native_c_compiler: x86_64-w64-mingw32-gcc -O2 -fno-strict-aliasing -fwrapv -mms-bitfields
bytecomp_c_libraries: -lws2_32 -lole32 -luuid -lversion -lshlwapi -lsynchronization -l:libpthread.a -lgcc_eh
native_c_libraries: -lws2_32 -lole32 -luuid -lversion -lshlwapi -lsynchronization -l:libpthread.a -lgcc_eh
native_ldflags:
native_pack_linker: x86_64-w64-mingw32-ld -r -o
native_compiler: true
architecture: amd64
model: default
int_size: 63
word_size: 64
system: mingw64
asm: x86_64-w64-mingw32-gcc -c
asm_cfi_supported: false
with_frame_pointers: false
ext_exe: .exe
ext_obj: .o
ext_asm: .s
ext_lib: .a
ext_dll: .dll
os_type: Win32
default_executable_name: camlprog.exe
systhread_supported: true
host: x86_64-w64-mingw32
target: x86_64-w64-mingw32
flambda: false
safe_string: true
default_safe_string: true
flat_float_array: true
function_sections: false
afl_instrument: false
tsan: false
windows_unicode: true
supports_shared_libraries: true
native_dynlink: true
naked_pointers: false
exec_magic_number: Caml1999X035
cmi_magic_number: Caml1999I035
cmo_magic_number: Caml1999O035
cma_magic_number: Caml1999A035
cmx_magic_number: Caml1999Y035
cmxa_magic_number: Caml1999Z035
ast_impl_magic_number: Caml1999M035
ast_intf_magic_number: Caml1999N035
cmxs_magic_number: Caml1999D035
cmt_magic_number: Caml1999T035
linear_magic_number: Caml1999L035
Here is me trying to bootstrap.
https://github.com/user-attachments/assets/7825b857-9846-40bd-a479-bdce62ff7420
It gets to the end and then stops suddenly. _boot/dune.exe doesn't exist.
Bootstrap doesn't have a log, so I now install dune into the current opam switch. That works fine which is good. I suppose opam is making sure the correct cygwin compat stuff is being used.
Dune has finished installing in the switch and I can check the version:
Let's try building bin/main.exe:
Oh no! π’
There is a big linking step at the end which is failing. Here is the bottom of _build/log:
Here is the linking command in _build/log:
_build/log
$ (cd _build/default && C:\Users\a\AppData\Local\opam\default\bin\ocamlopt.opt.exe -w @[email protected]@30..39@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -alert -unstable -g -o bin/main.exe otherlibs/ordering/ordering.cmxa vendor/pp/src/pp.cmxa otherlibs/dyn/dyn.cmxa C:/Users/a/AppData/Local/opam/default/lib/ocaml\unix\unix.cmxa otherlibs/stdune/dune_filesystem_stubs/dune_filesystem_stubs.cmxa -I otherlibs/stdune/dune_filesystem_stubs vendor/csexp/src/csexp.cmxa otherlibs/stdune/src/stdune.cmxa -I otherlibs/stdune/src src/dune_graph/dune_graph.cmxa vendor/incremental-cycles/src/incremental_cycles.cmxa src/dag/dag.cmxa vendor/fiber/src/fiber.cmxa src/dune_console/dune_console.cmxa src/memo/memo.cmxa src/dune_config/dune_config.cmxa C:/Users/a/AppData/Local/opam/default/lib/ocaml\threads\threads.cmxa src/dune_async_io/dune_async_io.cmxa vendor/re/src/dune_re.cmxa otherlibs/dune-glob/src/dune_glob.cmxa src/dune_metrics/dune_metrics.cmxa otherlibs/chrome-trace/src/chrome_trace.cmxa vendor/spawn/src/spawn.cmxa -I vendor/spawn/src src/dune_stats/dune_stats.cmxa -I src/dune_stats otherlibs/xdg/xdg.cmxa -I otherlibs/xdg vendor/build_path_prefix_map/src/build_path_prefix_map.cmxa vendor/uutf/dune_uutf.cmxa src/dune_sexp/dune_sexp.cmxa src/dune_util/dune_util.cmxa -I src/dune_util src/dune_digest/dune_digest.cmxa -I src/dune_digest src/predicate_lang/predicate_lang.cmxa src/fiber_util/fiber_util.cmxa src/dune_cache_storage/dune_cache_storage.cmxa src/dune_targets/dune_targets.cmxa src/dune_cache/dune_cache.cmxa otherlibs/dune-rpc/private/dune_rpc_private.cmxa otherlibs/dune-action-plugin/src/dune_action_plugin.cmxa src/dune_output_truncation/dune_output_truncation.cmxa src/csexp_rpc/csexp_rpc.cmxa -I src/csexp_rpc src/dune_rpc_client/dune_rpc_client.cmxa src/dune_thread_pool/dune_thread_pool.cmxa otherlibs/ocamlc-loc/src/ocamlc_loc.cmxa src/fsevents/fsevents.cmxa -I src/fsevents vendor/ocaml-inotify/src/ocaml_inotify.cmxa -I vendor/ocaml-inotify/src src/async_inotify_for_dune/async_inotify_for_dune.cmxa src/fswatch_win/fswatch_win.cmxa -I src/fswatch_win src/dune_file_watcher/dune_file_watcher.cmxa src/dune_engine/dune_engine.cmxa src/action_ext/action_ext.cmxa src/promote/promote.cmxa src/ocaml-config/ocaml_config.cmxa src/ocaml/ocaml.cmxa vendor/sha/sha.cmxa -I vendor/sha vendor/opam/src/core/opam_core.cmxa -I vendor/opam/src/core vendor/opam-file-format/opam_file_format.cmxa vendor/opam/src/format/opam_format.cmxa otherlibs/dune-private-libs/section/dune_section.cmxa src/dune_lang/dune_lang.cmxa src/fiber_event_bus/fiber_event_bus.cmxa otherlibs/dune-private-libs/meta_parser/dune_meta_parser.cmxa src/fs/fs.cmxa src/dune_findlib/dune_findlib.cmxa src/dune_vcs/dune_vcs.cmxa bin/.main.eobjs/native/build_info__Build_info_data.cmx otherlibs/dune-build-info/src/build_info.cmxa src/sat/sat.cmxa src/dune_pkg/dune_pkg.cmxa src/install/install.cmxa otherlibs/dune-site/src/private/dune_site_private.cmxa src/dune_threaded_console/dune_threaded_console.cmxa vendor/lwd/lwd/dune_lwd.cmxa vendor/notty/src/dune_notty.cmxa vendor/notty/src-unix/dune_notty_unix.cmxa -I vendor/notty/src-unix vendor/lwd/nottui/dune_nottui.cmxa src/dune_tui/dune_tui.cmxa src/dune_config_file/dune_config_file.cmxa src/dune_patch/dune_patch.cmxa src/scheme/scheme.cmxa src/dune_rules/dune_rules.cmxa src/upgrader/dune_upgrader.cmxa src/dune_pkg_outdated/dune_pkg_outdated.cmxa vendor/cmdliner/src/cmdliner.cmxa src/dune_rpc_server/dune_rpc_server.cmxa src/dune_rpc_impl/dune_rpc_impl.cmxa src/dune_rules_rpc/dune_rules_rpc.cmxa bin/.main.eobjs/native/dune__exe.cmx bin/.main.eobjs/native/dune__exe__Arg.cmx bin/.main.eobjs/native/dune__exe__Workspace_root.cmx bin/.main.eobjs/native/dune__exe__Common.cmx bin/.main.eobjs/native/dune__exe__Exit_code.cmx bin/.main.eobjs/native/dune__exe__Import.cmx bin/.main.eobjs/native/dune__exe__Util.cmx bin/.main.eobjs/native/dune__exe__Alias.cmx bin/.main.eobjs/native/dune__exe__Target.cmx bin/.main.eobjs/native/dune__exe__Build_cmd.cmx bin/.main.eobjs/native/dune__exe__Cache.cmx bin/.main.eobjs/native/dune__exe__Clean.cmx bin/.main.eobjs/native/dune__exe__Coqtop.cmx bin/.main.eobjs/native/dune__exe__Coq.cmx bin/.main.eobjs/native/dune__exe__Aliases_targets.cmx bin/.main.eobjs/native/dune__exe__Describe_contexts.cmx bin/.main.eobjs/native/dune__exe__Pkg_common.cmx bin/.main.eobjs/native/dune__exe__Describe_depexts.cmx bin/.main.eobjs/native/dune__exe__Describe_format.cmx bin/.main.eobjs/native/dune__exe__Describe_lang_compat.cmx bin/.main.eobjs/native/dune__exe__Describe_external_lib_deps.cmx bin/.main.eobjs/native/dune__exe__Describe_opam_files.cmx bin/.main.eobjs/native/dune__exe__Describe_pkg.cmx bin/.main.eobjs/native/dune__exe__Describe_pp.cmx bin/.main.eobjs/native/dune__exe__Describe_workspace.cmx bin/.main.eobjs/native/dune__exe__Installed_libraries.cmx bin/.main.eobjs/native/dune__exe__Package_entries.cmx bin/.main.eobjs/native/dune__exe__Print_rules.cmx bin/.main.eobjs/native/dune__exe__Printenv.cmx bin/.main.eobjs/native/dune__exe__Describe.cmx bin/.main.eobjs/native/dune__exe__Rpc_common.cmx bin/.main.eobjs/native/dune__exe__Diagnostics.cmx bin/.main.eobjs/native/dune__exe__Exec.cmx bin/.main.eobjs/native/dune__exe__External_lib_deps.cmx bin/.main.eobjs/native/dune__exe__Lock.cmx bin/.main.eobjs/native/dune__exe__Lock_dev_tool.cmx bin/.main.eobjs/native/dune__exe__Fmt.cmx bin/.main.eobjs/native/dune__exe__Format_dune_file.cmx bin/.main.eobjs/native/dune__exe__Help.cmx bin/.main.eobjs/native/dune__exe__Dune_init.cmx bin/.main.eobjs/native/dune__exe__Init.cmx bin/.main.eobjs/native/dune__exe__Install_uninstall.cmx bin/.main.eobjs/native/dune__exe__Internal_dump.cmx bin/.main.eobjs/native/dune__exe__Internal.cmx bin/.main.eobjs/native/dune__exe__Monitor.cmx bin/.main.eobjs/native/dune__exe__Doc.cmx bin/.main.eobjs/native/dune__exe__Ocaml_merlin.cmx bin/.main.eobjs/native/dune__exe__Top.cmx bin/.main.eobjs/native/dune__exe__Utop.cmx bin/.main.eobjs/native/dune__exe__Ocaml_cmd.cmx bin/.main.eobjs/native/dune__exe__Outdated.cmx bin/.main.eobjs/native/dune__exe__Print_solver_env.cmx bin/.main.eobjs/native/dune__exe__Validate_lock_dir.cmx bin/.main.eobjs/native/dune__exe__Pkg.cmx bin/.main.eobjs/native/dune__exe__Promotion.cmx bin/.main.eobjs/native/dune__exe__Build.cmx bin/.main.eobjs/native/dune__exe__Ping.cmx bin/.main.eobjs/native/dune__exe__Status.cmx bin/.main.eobjs/native/dune__exe__Rpc.cmx bin/.main.eobjs/native/dune__exe__Runtest.cmx bin/.main.eobjs/native/dune__exe__Shutdown.cmx bin/.main.eobjs/native/dune__exe__Subst.cmx bin/.main.eobjs/native/dune__exe__Ocamlformat.cmx bin/.main.eobjs/native/dune__exe__Ocamllsp.cmx bin/.main.eobjs/native/dune__exe__Tools.cmx bin/.main.eobjs/native/dune__exe__Upgrade.cmx bin/.main.eobjs/native/dune__exe__Main.cmx)
I guess ocamlopt thinks that the linker is some bash wrapper around the actual linker and is failing to call that?
Perhaps @dra27 knows more.
I guess
ocamloptthinks that the linker is some bash wrapper around the actual linker and is failing to call that?
By the way, the error is not from ocamlopt but from flexlink.
There is a big linking step at the end which is failing.
Just to clarify, the error that we are discussing now is different from the error that was discussed at the top of this issue, right?
In any case, I think what is going on is that flexlink uses bash to invoke the linker whenever the command-line length goes over a certain limit (see https://github.com/ocaml/flexdll/blob/f82196f15f4807d66b92138169bf5044c4ec05bb/reloc.ml#L207-L232), so your build is failing because you don't have bash in your PATH. Supposedly, this could be fixed without passing through bash by using response files, but this requires compiler-specifc logic. May be worth opening an issue upstream at https://github.com/ocaml/flexdll/issues.
For your immediate issue, I don't see an easy way to work around it without doing your build from within Cygwin at the moment.
There is a big linking step at the end which is failing.
Just to clarify, the error that we are discussing now is different from the error that was discussed at the top of this issue, right?
Yes, it appears to be different. I originally thought it might be related due to the linking failure.
In any case, I think what is going on is that
flexlinkusesbashto invoke the linker whenever the command-line length goes over a certain limit (see ocaml/flexdll@f82196f/reloc.ml#L207-L232), so your build is failing because you don't havebashin your PATH. Supposedly, this could be fixed without passing throughbashby using response files, but this requires compiler-specifc logic. May be worth opening an issue upstream at ocaml/flexdll/issues.
I'll look into it.
For your immediate issue, I don't see an easy way to work around it without doing your build from within Cygwin at the moment.
I managed to setup OCaml for windows last year but I don't remember how. I seem to recall having setup both the gnu and msvc versions separately.
In any case, this is not such a big issue for me, but I do feel bad for our poor Windows users.
Looks like there is already an issue here: https://github.com/ocaml/flexdll/issues/138