# Dune build error with version \>= 2

**URL:** <https://discuss.ocaml.org/t/dune-build-error-with-version-2/8459>\
**Category:** Learning\
**Tags:** dune\
**Created:** [September 10, 2021, 12:36pm UTC](https://discuss.ocaml.org/t/dune-build-error-with-version-2/8459 "2021-09-10T12:36:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanette](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/sanette/32/1645_2.png) [@sanette](https://discuss.ocaml.org/u/sanette)\
**Post date:** [September 10, 2021, 12:36pm UTC](https://discuss.ocaml.org/t/dune-build-error-with-version-2/8459/1 "2021-09-10T12:36:35Z")

</div>

Hi, I noticed a strange behaviour with, for instance, [GitHub - sanette/tsdl-image: OCaml SDL2\_image bindings to go with Tsdl](https://github.com/sanette/tsdl-image)

```auto
$ dune build 
      ocamlc test/test.bc (exit 2)
(cd _build/default && /home/san/.opam/4.08.1/bin/ocamlc.opt -w @1..3@5..28@30..39@43@46..47@49..57@61..62-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -o test/test.bc /home/san/.opam/4.08.1/lib/ocaml/unix.cma /home/san/.opam/4.08.1/lib/ocaml/bigarray.cma /home/san/.opam/4.08.1/lib/integers/integers.cma /home/san/.opam/4.08.1/lib/ctypes/ctypes.cma /home/san/.opam/4.08.1/lib/ocaml/threads/threads.cma /home/san/.opam/4.08.1/lib/ctypes/ctypes-foreign-base.cma /home/san/.opam/4.08.1/lib/ctypes/ctypes-foreign-threaded.cma /home/san/.opam/4.08.1/lib/tsdl/tsdl.cma src/tsdl_image.cma test/.test.eobjs/byte/dune __exe__ Test.cmo)
/usr/bin/ld : ne peut trouver -lctypes-foreign-threaded_stubs
/usr/bin/ld : ne peut trouver -lctypes-foreign-base_stubs
/usr/bin/ld : ne peut trouver -lctypes_stubs
/usr/bin/ld : ne peut trouver -lintegers_stubs
/usr/bin/ld : ne peut trouver -lintegers_stubs
collect2: error: ld returned 1 exit status
File "_none_", line 1:
Error: Error while building custom runtime system

```

BUT:

1. `dune test` works
2. `dune build -p tsdl-image` works (and hence `opam install .` works.)
3. If I switch to `(lang dune 1.11)` in `dune-project` then `dune build` works.

So, what should I do to make `dune build` work with `(lang dune 2.7)`?

---

<div class="post-metadata">

**Author:** ![CraigFe](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/craigfe/32/1989_2.png) [@CraigFe](https://discuss.ocaml.org/u/CraigFe)\
**Post date:** [September 10, 2021, 12:51pm UTC](https://discuss.ocaml.org/t/dune-build-error-with-version-2/8459/2 "2021-09-10T12:51:46Z")

</div>

Dune 2.0 [changes the default target](https://github.com/ocaml/dune/issues/1220) from `@install` to `@all`, so upgrading to `(lang dune 2.0)` will cause `dune build` to attempt to build more targets. In particular, executables with no `public_name` field (likely including your test binary) will be built by default whereas previously they were not.

If you run `dune build @all` on the project with `(lang dune 1.11)`, do you get the same error?

---

<div class="post-metadata">

**Author:** ![sanette](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/sanette/32/1645_2.png) [@sanette](https://discuss.ocaml.org/u/sanette)\
**Post date:** [September 10, 2021, 1:15pm UTC](https://discuss.ocaml.org/t/dune-build-error-with-version-2/8459/3 "2021-09-10T13:15:07Z")

</div>

> [@CraigFe](#):
>
> If you run `dune build @all` on the project with `(lang dune 1.11)` , do you get the same error?

indeed, yes!  
thanks for the explanation.  
But, I’m still missing something. Since `dune test` and `dune exec test/text.exe` both work, what is the ‘target’ that fails?

---

<div class="post-metadata">

**Author:** ![CraigFe](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/craigfe/32/1989_2.png) [@CraigFe](https://discuss.ocaml.org/u/CraigFe)\
**Post date:** [September 10, 2021, 1:33pm UTC](https://discuss.ocaml.org/t/dune-build-error-with-version-2/8459/4 "2021-09-10T13:33:09Z")

</div>

> [@sanette](#):
>
> what is the ‘target’ that fails?

I’d guess the failing target is the bytecode test executable (`dune exec ./test/test.bc`); looks like your executable isn’t linking properly when compiled with `ocamlc` (and not `ocamlopt`).

You may want to add `(modes exe)` to the corresponding stanza to [disable the bytecode target](https://dune.readthedocs.io/en/stable/dune-files.html#linking-modes). This is the default post-2.0 anyway, so you can upgrade to get the same effect.

---

<div class="post-metadata">

**Author:** ![sanette](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/sanette/32/1645_2.png) [@sanette](https://discuss.ocaml.org/u/sanette)\
**Post date:** [September 10, 2021, 1:39pm UTC](https://discuss.ocaml.org/t/dune-build-error-with-version-2/8459/5 "2021-09-10T13:39:25Z")

</div>

exactly, `(modes exe)` does the trick, thanks!

(what do you mean by ‘default post-2.0’? I’m currently using dune 2.9.1)

---

<div class="post-metadata">

**Author:** ![CraigFe](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/craigfe/32/1989_2.png) [@CraigFe](https://discuss.ocaml.org/u/CraigFe)\
**Post date:** [September 10, 2021, 1:40pm UTC](https://discuss.ocaml.org/t/dune-build-error-with-version-2/8459/6 "2021-09-10T13:40:57Z")

</div>

Post `(lang dune 2.0)`, I should say 🙂

The Dune team are quite good at tying functional changes to language version, so the actual Dune version you’re using shouldn’t matter much w.r.t. correctness (except in that it places an upper bound on the lang version that you can use).

---

<div class="post-metadata">

**Author:** ![sanette](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/sanette/32/1645_2.png) [@sanette](https://discuss.ocaml.org/u/sanette)\
**Post date:** [September 10, 2021, 1:42pm UTC](https://discuss.ocaml.org/t/dune-build-error-with-version-2/8459/7 "2021-09-10T13:42:01Z")

</div>

but I was using `(lang dune 2.7)`

---

<div class="post-metadata">

**Author:** ![CraigFe](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/craigfe/32/1989_2.png) [@CraigFe](https://discuss.ocaml.org/u/CraigFe)\
**Post date:** [September 10, 2021, 1:43pm UTC](https://discuss.ocaml.org/t/dune-build-error-with-version-2/8459/8 "2021-09-10T13:43:57Z")

</div>

I’m not sure what’s happening in that case. My understanding is that from dune lang 2.0, `(modes exe)` is the default for executables (as this is what I interpret [from the documentation](https://dune.readthedocs.io/en/stable/dune-files.html#executable)).

---

<div class="post-metadata">

**Author:** ![sanette](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/sanette/32/1645_2.png) [@sanette](https://discuss.ocaml.org/u/sanette)\
**Post date:** [September 10, 2021, 1:45pm UTC](https://discuss.ocaml.org/t/dune-build-error-with-version-2/8459/9 "2021-09-10T13:45:46Z")

</div>

maybe this is the default for `executable` stanza, but not for `test`…
