dune icon indicating copy to clipboard operation
dune copied to clipboard

Confused with dune exec ./bin/main.exe, why file not exists, but still can execute

Open cnmade opened this issue 2 years ago • 7 comments

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 of dune --version): $ dune --version 3.2.0

  • Version of ocaml (output of ocamlc --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.

cnmade avatar Jun 20 '22 03:06 cnmade

This foolish me , i can not understand it.

cnmade avatar Jun 20 '22 03:06 cnmade

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 avatar Jun 20 '22 05:06 nojb

@nojb oh, god, this should see in the document.

cnmade avatar Jun 20 '22 06:06 cnmade

Which information is missing from https://dune.readthedocs.io/en/stable/usage.html?highlight=_build#interpretation-of-targets ?

bobot avatar Jun 20 '22 08:06 bobot

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.

cnmade avatar Jun 20 '22 09:06 cnmade

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.

Alizter avatar Jun 20 '22 12:06 Alizter

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.

lthibault avatar Aug 14 '22 22:08 lthibault