ocamlocaml-dune

Building "hello world" with ocaml dune


Following the tutorial at https://dune.readthedocs.io/en/stable/quick-start.html, I created a file hello_world.ml containing

print_endline "Hello, world!"

and a file dune containing

(executable
 (name hello_world))

and then typed

dune build hello_world.exe

but it complains about errors in other (completely unrelated) files.

Is it possible that dune looks at other files even though they are not mentioned in the dune file (even recursively) ? And how to prevent it ?


Solution

  • Yes, dune will search for all files that have *.ml or *.re files in the current folder. To disable this behavior use the modules stanza and explicitly specify which modules comprise your executable. For example, if it is made of hello_world.ml and utilities.ml compilation units, then the following specification will work for you,

    (executable 
      (name hello_world)
      (modules hello_world utilities))