The following examples come from the dune quickstart, where more explanations can be found.


This will build into an executable as _build/default/hello_world.exe.

 (name hello_world)
 (libraries lwt.unix))


 (name mylib)
 (libraries re lwt))

The library will be composed of all the modules in the same directory. Outside of the library, module Foo will be accessible as Mylib.Foo, unless you write an explicit file.

This library can be made available as an opam package if you replace (name mylib) by (public_name mylib) and write a mylib.opam file.


 (name my_test_program))

With this, the tests can be run using dune runtest.

It will run the test program (the main module is and error if it exits with a nonzero code.

Mix and match

A typical project will have several dune files referring to each other.

For example:

├── bin
│   ├── dune
│   └──
├── lib
│   ├── dune
│   ├──
│   ├── mylib.mli
│   └── mylib.opam
└── test
    ├── dune
  • bin/dune defines an executable depending on mylib
  • test/dune defines a test executable depending on mylib

Note that the bin, lib, test directory names are not meaningful to dune.