dune
dune copied to clipboard
Confused with dune exec ./bin/main.exe, why file not exists, but still can execute
Expected Behavior
The file should exists
Actual Behavior
$ dune exec ./bin/main.exe
Hello, World!
$ ls -l ./bin/main.exe
ls: ./bin/main.exe: No such file or directory
$ cat bin/main.ml
let () = print_endline "Hello, World!"
Reproduction
$ dune init proj helloworld
Success: initialized project component named helloworld
$ cd helloworld
We can build our program with dune build:
$ dune build
When we change our program, we can type dune build again to make a new executable. To run the program, we can use:
$ dune exec ./bin/main.exe
Hello, World!
$ ls -l ./bin/main.exe
ls: ./bin/main.exe: No such file or directory
Specifications
-
Version of
dune
(output ofdune --version
): $ dune --version 3.2.0 -
Version of
ocaml
(output ofocamlc --version
) $ ocamlc --version 4.12.0 -
Operating system (distribution and version): MacOS 12 Intel cpu
Additional information
I can not understand, the file ./bin/main.exe not exists, why we can run dune exec ./bin/main.exe
and i got the output?
Why, i can not read why from the document, document not tell us.
very strange.
For every document we know with unix/linux.
There should be a file exists, then we can exec that file/programm.
If the file not exists in the directory/path, we will get the file not found error message.
This foolish me , i can not understand it.
Note that Dune generally puts the build artifacts in a separate _build
directory, so the file in question can be found at _build/default/bin/main.exe
.
@nojb oh, god, this should see in the document.
Which information is missing from https://dune.readthedocs.io/en/stable/usage.html?highlight=_build#interpretation-of-targets ?
can't see why ./bin/main.exe
not exists. document not explain that .
$ ls -l ./bin/main.exe
ls: ./bin/main.exe: No such file or directory
It really not exists a file in the ./bin/ directory.
The reason dune exec ./bin/main.exe
works is because Dune builds the executable and puts it in a ./.bin/
folder. All of this is happening in _build/default
. Dune builds everything in the _build/default
folder and doesn't contaminate the source directory (unless explicitly instructed to).
I am not sure where you found out about .bin
however, but it is not the recommended way to run things. With public executables, you will find them in _build/install/default/bin
so you can think of dune exec main.exe
as meaning dune build yourpackage.install; ./_build/install/default/bin/main.exe
.
I am not sure where you found out about .bin however, but it is not the recommended way to run things.
@cnmade is doing exactly what the Quickstart tutorial recommends. I arrived at this issue because I am likewise confused. These details really ought to be made clear in the tutorial.