4

I took over an ocaml project that consists of a main program and a library, but the library is built indepenently. Linking the main program was up until now possible with "ocamlopt -I mylib.cmxa myprogram.ml" - but I had problems using opam libraries with ocamlopt so I decided to move to "dune" instead.

My question is: How do I link with the ocaml library using dune so that the result is the same like the ocamlopt line above did?

Marius Melzer
  • 863
  • 1
  • 7
  • 10

1 Answers1

1

It would help to see the structure of your project. However, in general if you have a project structured like this:

root/
|—— dune-project
|—— lib/
|  |—— dune
|  |—— lib.ml
|
|—— bin/
|  |—— dune
|  |—— bin.ml

Then your lib/dune will look something like

(library
 (name        mylib)
 (public_name mylib)
 (libraries core async))

and your bin/dune will simply list this library among its dependencies

(executable
 (name mybin)
 (libraries mylib))

For further guidance, consult the hello_world example project in the dune repository.

Shon
  • 3,989
  • 1
  • 22
  • 35