Custom toplevels and dune

I want to build a bytecode executable (as it embed an OCaml toplevel) that uses some C libraries, such as linenoise. However, the description of a normal executable with (modes native) and (flags :standard -linkall -custom) with the appropriate library dependencies only gives me linker errors such as:

/usr/bin/ld: cannot find -llinenoise_stubs

which are not a problem when building native binaries, with the appropriate LD_LIBRARY_PATH. But for the custom executable I have no idea how to tell dune what directories to include…

Manually passing -custom is generally not great. Dune needs to know what files the compiler invocation is going to need, and -custom changes this set of files from static library files to dll files. Since Dune is not able to parse the flags passed to the compiler, if you manually pass -custom dune will still think that the compiler will read liblineoise_stubs.a rather than dlllineoise_stubs.so.

Fortunately, since Dune 2.2.0 you can use (modes byte_complete) to build a custom bytecode executable. What is more, if your compiler is recent enough byte_complete will map to the new -output-complete-exe option which is now the prefered way of building standalone bytecode programs. Also, -custom is now deprecated.

I tried byte_complete on the advice of rgrinberg, but it still fails (with dune 2.5) with:

Error: No installable mode found for this executable.
One of the following modes is required:
- exe
- native
- byte

(edit: I should also specify this is on OCaml 4.08)

Hmm, I guess this could be improved in dune. In the meantime, you can remove the public_name field and instead use an explicit install.

1 Like