2

Suppose I want to use dune to build a project that has a flat directory structure:

my_project/
├── dune
├── basics.ml
├── basics.mli
├── utils.ml
├── utils.mli
└── main.ml

main.ml is the main program (the entry point). main.ml depends on utils.ml, while utils.ml in turn depends on basics.ml. main.ml calls functions in utils.ml using prefix Utils (e.g. Utils.example_function x y).

The question: What should I write in the dune file in order to compile this project?

So far, all the dune examples I have seen use this directory structure instead:

my_project/
├── dune
├── main.ml
└── mylib
    ├── dune
    ├── basics.ml
    ├── basics.mli
    ├── utils.ml
    └── utils.mli

Where my_project/dune is:

(executable
  (name main)
  (libraries mylib))

and my_project/mylib/dune is:

(library (name mylib))

and main.ml calls functions in utils.ml using prefix Mylib.Utils (e.g. Mylib.Utils.example_function x y).

I do not want this directory structure; I do not want to create a separate directory for utils.ml and basics.ml. I want all source files to be in the same directory as main.ml. Is there a way to do this using dune?

Flux
  • 9,805
  • 5
  • 46
  • 92

1 Answers1

2

You have to list modules of each library/executable for this to work:

(executable
  (name main)
  (modules main)
  (libraries mylib))

(library
  (name mylib)
  (modules utils basics))

Or you can just put everything in your executable:

(executable
  (name main)
  (modules basics main utils)) ; and this line is not needed anymore
yehudi
  • 132
  • 1
  • 3