0

I am experiencing some issues when trying to create a .cma file (library) with the dune utility. I have the following project tree:

.
├── _build
│   ├── default
│   │   ├── dune
│   │   └── lib
│   │       ├── a.a
│   │       ├── a.cma
│   │       ├── a.cmxa
│   │       ├── a.cmxs
│   │       ├── a.ml
│   │       └── dune
│   └── log
├── dune
├── dune-project
└── lib
    ├── a.ml
    └── dune

Where a.ml declares a very simple function f, as an example. When I run directly ocamlc -o a.cma -a a.ml, and then fire up utop a.cma, I am able to perform, as desired, the following command:

utop # A.f;;
- : int -> int = <fun>

On the other hand, after one use of dune build (which generates the _build directory and its sub-directories), the _build/default/lib/a.cma file that I get takes ten times as much space as the manually-generated one, and more importantly, does not work. Both commands utop _build/default/lib/a.cma and cd _build/default/lib; utop a.cma are unsuccesful and I am unable to use the module A:

utop # A.f;;
Line 1, characters 0-3:
Error: Unbound module A

I know about the dune utop command, but what if I want to export/share my library elsewhere, where dune is not installed? What am I supposed to do? Am I using dune the wrong way? Thank you in advance


PS: File content:

lib/dune

(library
 (name a))
Loutr_
  • 3
  • 3

1 Answers1

0

You need to make visible the bytecode object files in .a.objs/byte. For instance with:

#directory ".a.objs/byte"

(Those files are installed as usual for library users)

Also note that dune is by default in wrapped mode: the module M from library Lib is accessible as Lib.M, except if the user defines an entry point module with the the same name Lib as the whole library.

octachron
  • 17,178
  • 2
  • 16
  • 23
  • Thanks! Do you have any explanation as to why it is like this (i.e. `.cmi` file inside this hidden folder and... 'useless' `.cmi` file next to the `.cma` file)? standard libraries don't have such folders in my installation. – Loutr_ Feb 23 '21 at 09:47
  • The compilation artifacts in build are not really intended to be directly used (without an installation step). Those issues are not present once the library installed. – octachron Feb 23 '21 at 13:38