While finding the particular opam package to install, in order to have certain findlib packages available (e.g. ppx_compare, ppx_sexp_conv) isn’t trivial, after that, well, using ocamlfind makes invoking PPX derivers and rewriters pretty straightforward.
The recommended way these days is to use dune on WSL
Who does recommend this? (Serious question).
The problem I have with dune (as a relatively new OCaml user) is that it
needs a configuration file - thus requiring me to learn yet another
configuration language.
Whereas ocamlbuild can be invoked with arbitrary arguments ad-hoc.
particularly the 3rd point since it shows how to use dune, libraries, ppx, some conventional way of using make files, opam switches, code formatting and linting. and it does it without assuming previous knowledge. TBH I would have quit trying OCaml if it wasn’t for this tutorial.
also check out https://dune.readthedocs.io/en/stable/usage.html
Yes, the -linkpkg option works. Thanks a lot. I will look at the dune option, but it is perhaps overkill for a little example made to learn one or two things.
[begin joke]
Why, Jane Street, of course! It’s all part of developer marketing!
[end joke]
But seriously, there is never any need to use dune, and I’ve built quite complex projects with many, many interesting dependencies on both OCaml and C/C++ code, lots of PPX rewriters, and all using Makefiles. it’s not hard, and frankly, I don’t understand why people want all these other tools. But hey, de gustibus and all that.
The OCaml Platform maintainers recommend it. See OCaml Platform for details.
Yeah, it can be a bit of a pain, but it doesn’t take much to get started–see https://dune.build/ , and it pays for itself over and over again with fast incremental builds, as many times as you run the builds.
This is only true for the simplests of builds; you will need to add a _tags file and/or a myocamlbuild.ml plugin as your project grows… For such a simple project, the necessary dune metadata is just 2 or 3 lines.
Other advantages of dune over ocamlbuild are: much faster than ocamlbuild (but you will hardly notice this in a little example), automatic generation of .merlin files, native Windows support, composable (just drop a clone of a dune project inside your repository and it becomes available for use), native support for building “wrapped” libraries using module aliases, etc. And also, it is currently maintained
Most of these are also advantages with respect to make, to which we could add out-of-tree builds, checksum-based global dependency calculation (which makes highly parallel builds painless), a lot of built-in knowledge about OCaml which needs to be recreated when using make (eg building C/C++ stubs under both Unix and Windows, both as static libraries for native use and shared libraries for toplevel use), an efficient ppx compilation pipeline, etc.
But indeed you will only notice many of this advantages as your project grows; for a small program of a couple of files, any of the tools will suffice easily.