Build multiple OCaml executables in one Dune Project

Search for a command to run...

No comments yet. Be the first to comment.
Remember my post about switching to VSCode? Well, plot twist: the very next day after publishing it, I switched to WebStorm. And guess what? I've been on JetBrains IDEs ever since. I know, I know. Another "why I switched editors" post. But hear me ou...

I had been doing some basic interpreter work in Go and wanted to redo it in another language to solidify my understanding. Naturally, I chose Odin, it’s another great language, with a Go-like, easy-to-approach syntax and no unnecessary complexity. I ...

Why Emacs Keybindings? I've always preferred Emacs-style editing, especially the way it handles cursor movement and text manipulation. Even though I have switched to using VSCode for most of my development work, I often found myself missing the intui...

In my previous post about building C/C++ projects with CMake, I shared a simple CMakeLists.txt setup for compiling a basic project. Today, I’ll dive into a specific need that many developers encounter: linking libraries directly from project folders ...

Some time ago, I wrote a post about using Vim to look cool and why that’s not a good idea. Now, funny enough, here I am—having switched to VSCode after years of hopping between Vim and Emacs. This isn’t one of those "Vim sucks, I'm going back to VSCo...

Follow these steps to create a new dune project if you don't already have one.
First, initiate the project structure.
dune init project foo
It will create a project structure like this

The bin folder contains the source file for the main executable main.ml
the bin/dune file has the build instruction for the executable, it'll look something like this.
(executable
(public_name foo)
(name main)
(libraries foo))
Let's see how to add support to build another executable called bar, which we'll write in the file called bar.ml.
First, create a file called bar.ml in the bin directory.
Then you can update the bin/dune file support multiple executables like below.
(executables
(public_names foo bar)
(name main bar)
(libraries foo))
You can use the following commands to run the different executables.
dune exec ./bin/main.exe
dune exec ./bin/bar.exe
To build you can run following
dune build ./bin/main.exe
dune build ./bin/bar.exe
To run the built executables
./_build/default/bin/main.exe
./_build/default/bin/bar.exe