From jbuilder to dune with a Ctypes project

I have library based on Ctypes and I use jbuilder to build and test it. I want to use dune now but I am not able to run my tests with dune. For those that prefer to see the modifications via the github interface here is the link

In my project, I have a configurator that loads some C flags for Ctypes like described here :

so I have 3 jbuild files that need to be transformed to 3 dune files:

in the config directory:

(jbuild_version 1)

 ((name discover)
  (libraries (base stdio configurator))))

is transformed to

 (name discover)
 (libraries base stdio configurator))

the jbuild file in my lib directory :

(jbuild_version 1)

 ((name        GObject_introspection)
  (public_name gobject-introspection)
  (libraries (ctypes ctypes.foreign str))
  (c_flags         (:include c_flags.sexp))
  (c_library_flags (:include c_library_flags.sexp))
  (ocamlopt_flags (-ccopt ("-Wl,-no-as-needed")))
 ((targets (c_flags.sexp
  (deps    (../config/discover.exe))
  (action  (run ${<} -ocamlc ${OCAMLC}))

is transformed to:

 (name        GObject_introspection)
  (public_name gobject-introspection)
  (libraries ctypes ctypes.foreign str)
  (c_flags         (:include c_flags.sexp))
  (c_library_flags (:include c_library_flags.sexp))
  (ocamlopt_flags (-ccopt ("-Wl,-no-as-needed")))

  (targets c_flags.sexp c_library_flags.sexp)
  (deps    (:x ../config/discover.exe))
  (action  (run %{x} -ocamlc %{ocamlc}))

and the jbuild file in my test directory:

(jbuild_version 1)

 ((names (test))
  (libraries   (GObject_introspection oUnit ctypes ctypes.foreign))

 ((name    runtest)
  (deps    (test.exe))
  (action  (run ${<}))))

is transformed in :

 (names test)
 (libraries GObject_introspection oUnit ctypes ctypes.foreign)

  (name    runtest)
  (deps    (:x test.exe))
  (action  (run %{x})))

Even though I did not modify any lines of code, I am not able to run my tests anymore both localy or on Travis.

for example on my computer, I have the following output:

dune runtest                                         
      ocamlc lib/.GObject_introspection.objs/GObject_introspection__Registered_type_info.{cmi,cmti} (exit 2)
(cd _build/default && /home/cedlemo/.opam/default/bin/ocamlc.opt -w @a-4-29-40-41-42-44-45-48-58-59-60-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I lib/.GObject_introspection.objs -I /home/cedlemo/.opam/default/lib/bytes -I /home/cedlemo/.opam/default/lib/ctypes -I /home/cedlemo/.opam/default/lib/integers -I /home/cedlemo/.opam/default/lib/ocaml/threads -no-alias-deps -open GObject_introspection -o lib/.GObject_introspection.objs/GObject_introspection__Registered_type_info.cmi -c -intf lib/Registered_type_info.mli)
File "lib/Registered_type_info.mli", line 22, characters 0-12:
Error (warning 33): unused open Foreign.
      ocamlc lib/.GObject_introspection.objs/GObject_introspection__Types.{cmi,cmti} (exit 2)
(cd _build/default && /home/cedlemo/.opam/default/bin/ocamlc.opt -w @a-4-29-40-41-42-44-45-48-58-59-60-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I lib/.GObject_introspection.objs -I /home/cedlemo/.opam/default/lib/bytes -I /home/cedlemo/.opam/default/lib/ctypes -I /home/cedlemo/.opam/default/lib/integers -I /home/cedlemo/.opam/default/lib/ocaml/threads -no-alias-deps -open GObject_introspection -o lib/.GObject_introspection.objs/GObject_introspection__Types.cmi -c -intf lib/Types.mli)
File "lib/Types.mli", line 22, characters 0-12:
Error (warning 33): unused open Foreign.
    discover lib/c_flags.sexp,lib/c_library_flags.sexp
==================== Configurator ================
>>>>>>>>>>>>>>>>>>>>> libs : <<<<<<<<<<<<<<<<<<<<<<
(-L/usr/lib/../lib -lffi -lgirepository-1.0 -lgobject-2.0 -lglib-2.0 -L/usr/lib/x86_64-linux-gnu -L/usr/lib)
>>>>>>>>>>>>>>>>>>>>> flags : <<<<<<<<<<<<<<<<<<<<<<
(-I/usr/lib/libffi-3.2.1/include -I/usr/include/gobject-introspection-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -pthread -I/usr/lib/libffi-3.2.1/include -I/usr/include -I/usr/include/x86_64-linux-gnu)
==================== Configurator ================

I can not figure out what is wrong.

Probably because dune activates the --dev profile by default now. Which ends up failing your build under the stricter warning regimen. Try building your code with $ dune build --profile release and see if that works.

Btw, if you haven’t already, consult with the page for migrating to the new configurator (which is built in with dune):


When I tried to use the new configurator :

diff --git a/config/ b/config/
index 654481a..7d5a438 100644
--- a/config/
+++ b/config/
@@ -1,6 +1,6 @@
 open Base
 open Stdio
-module C = Configurator
+module C = Configurator.V1
 let write_sexp fn sexp =
   Out_channel.write_all fn ~data:(Sexp.to_string sexp)
diff --git a/config/dune b/config/dune
index e2ed62f..36b2244 100644
--- a/config/dune
+++ b/config/dune
@@ -1,3 +1,3 @@
  (name discover)
- (libraries base stdio configurator))
+ (libraries base stdio dune.configurator))
diff --git a/gobject-introspection.opam b/gobject-introspection.opam
index dfd2063..2c0a406 100644
--- a/gobject-introspection.opam
+++ b/gobject-introspection.opam
@@ -16,5 +16,4 @@ depends: [
-  "configurator"

I have the following error. :

File "_none_", line 1:
Error: Files /home/cedlemo/.opam/default/lib/dune/stdune/stdune.cmxa
       and /home/cedlemo/.opam/default/lib/base/caml/caml.cmxa
       make inconsistent assumptions over interface Caml

If you want I can send a PR to update the documentation here :

Thanks for reporting this. This is indeed a bug that I’ve reported:

For now, I suggest that you simple drop the dependence on Stdio/Base. Configurator.V1.Flags should contain everything you need.

1 Like