Skip to content

Instantly share code, notes, and snippets.

Created April 9, 2019 18:36
What would you like to do?
Notes on using `dune` for OCaml.


A first pass

A library and then an executable that uses that library.

A simple library

Create a folder called foo:

mkdir foo
cd foo

Create a file called with these contents:

let greeting name = Printf.printf "Hello, %s\n%!" name

Create a foo.opam file with these contents:

opam-version: "2.0"
name: "foo"
version: "0.1"
synopsis: "One-line description"
description: """
Longer description
maintainer: "Name <email>"
authors: "Name <email>"
license: "MIT"
homepage: ""
bug-reports: ""
dev-repo: "git+"

Create a dune file with these contents:

  (name foo)
  (public_name foo))

Create a Makefile with these contents:

all: build.local

        opam pin remove -y .
        dune uninstall
        dune clean

        dune build
        opam pin add -y .

Build it:


Confirm that opam and ocamlfind can find it:

opam find | grep foo
ocamlfind query foo

Confirm you can use it. Open utop, then:

#use "topfind";;
#require "foo";;
Foo.greeting "Jorge!";;

Create a .gitignore file, with these contents:


Initialize and save to git:

git init
git add -A
git commit -m "Initial commit."

An executable that uses the library

Create another folder, called foozball:

cd ..
mkdir foozball
cd foozball

Create a file called with these contents:

Foo.greeting "Jorge.";

Create a dune file:

  (name foozball)
  (libraries foo))

Create a Makefile:

exe = foozball.exe

all: clean build

        dune clean

        dune build $(exe)

Create a .gitignore file:


Build it:


Try it out:


Add everything to git and commit:

git init
git add -A
git commit -m "Initial commit."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment