简体   繁体   中英

Can OCaml dune build a project that has a flat directory structure?

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 (eg Utils.example_function xy ).

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 (eg Mylib.Utils.example_function xy ).

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM