# \[dune\] How to specify dependency to an executable?

**URL:** https://discuss.ocaml.org/t/dune-how-to-specify-dependency-to-an-executable/8888
**Category:** Learning
**Tags:** dune
**Created:** [November 25, 2021, 3:20pm UTC](https://discuss.ocaml.org/t/dune-how-to-specify-dependency-to-an-executable/8888 "2021-11-25T15:20:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Kakadu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/kakadu/32/1204_2.png) [@Kakadu](https://discuss.ocaml.org/u/Kakadu)
#### Post date: [November 25, 2021, 3:20pm UTC](https://discuss.ocaml.org/t/dune-how-to-specify-dependency-to-an-executable/8888/1 "2021-11-25T15:20:28Z")

</div>

I’m developing an executable and want to cram-test it. But I don’t know a way to add a strict dependency from tests to my executable. [MVP](https://github.com/Kakadu/dune-test-exec-dependencies). The call `dune build @install && dune test ` helps but I want a dependency…

```auto
➜ dune-exec-cram-demo git:(master) ✗ cat test.t/run.t 4.12.1+flambda
  $ dune build
$ echo $PATH
  $ which asdf
  [1]
  $ asdf
  asdf: not found
  [127]
  $ qwe
  qwe: not found
  [127]
➜ dune-exec-cram-demo git:(master) ✗ cat test.t/dune 4.12.1+flambda
(cram
 (deps
  %{workspace_root}/src/asdf
  %{workspace_root}/src/asdf.exe
  %{bin:asdf}
  %{bin:qwe}
  %{workspace_root}/qwe.exe))

(library
 (name lib1)
 (modules lib1))

```

---

<div class="post-metadata">

### Author: ![Leonidas](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/leonidas/32/4039_2.png) [@Leonidas](https://discuss.ocaml.org/u/Leonidas)
#### Post date: [November 25, 2021, 3:44pm UTC](https://discuss.ocaml.org/t/dune-how-to-specify-dependency-to-an-executable/8888/2 "2021-11-25T15:44:03Z")

</div>

In `dune-release` we use the following to depend on our binary that is installed (has a `public_name`) and one that is not installed (just a helper for cleaning test output):

```auto

(env
 (_
  (binaries
   (../helpers/make_dune_release_deterministic.exe as
     make_dune_release_deterministic))))

(cram
 (deps %{bin:dune-release} %{bin:make_dune_release_deterministic}))

```

---

<div class="post-metadata">

### Author: ![bnguyenvanyen](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@bnguyenvanyen](https://discuss.ocaml.org/u/bnguyenvanyen)
#### Post date: [November 25, 2021, 3:49pm UTC](https://discuss.ocaml.org/t/dune-how-to-specify-dependency-to-an-executable/8888/3 "2021-11-25T15:49:03Z")

</div>

So weirdly I don’t get the same result as you, and for me it works…  
I don’t think the dune files inside the `test.t` should do anything according to [Writing and Running Tests — dune documentation](https://dune.readthedocs.io/en/latest/tests.html#directory-tests)  
It also works for me without `test.t/dune` and `test.t/dune-project`, but with

```auto
> cat test.t/run.t
  $ which asdf
  $ asdf
  $ qwe
> git diff dune
diff --git a/dune b/dune
index 1d907b5..a680c9b 100644
--- a/dune
+++ b/dune
@@ -2,3 +2,11 @@
  (public_name qwe)
  (package package1)
  (name qwe))
+
+
+(cram
+ (deps
+ %{bin:asdf}
+ %{bin:qwe}
+ )
+)
> dune clean && dune runtest
diff --git a/../../../default/test.t/run.t b/test.t/run.t.corrected
index f9f6a51..9bab56a 100644
--- a/../../../default/test.t/run.t
+++ b/test.t/run.t.corrected
@@ -1,3 +1,6 @@
   $ which asdf
+ path/to/dune-test-exec-dependencies/_build/install/default/bin/asdf
   $ asdf
+ Hello, World!
   $ qwe
+ Hello, World!

```

Does this work for you ?

---

<div class="post-metadata">

### Author: ![Kakadu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/kakadu/32/1204_2.png) [@Kakadu](https://discuss.ocaml.org/u/Kakadu)
#### Post date: [November 25, 2021, 4:20pm UTC](https://discuss.ocaml.org/t/dune-how-to-specify-dependency-to-an-executable/8888/4 "2021-11-25T16:20:48Z")

</div>

Thanks @bnguyenvanyen

I needed to specify that executables are used in cram tests in dune file where I define executables, not in dune files for tests. Wondering why dune didn’t show any warning about that…
