# Using an executable as library in dune

**URL:** <https://discuss.ocaml.org/t/using-an-executable-as-library-in-dune/11249>\
**Category:** Ecosystem\
**Tags:** dune\
**Created:** [January 26, 2023, 12:06am UTC](https://discuss.ocaml.org/t/using-an-executable-as-library-in-dune/11249 "2023-01-26T00:06:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vm2p](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vm2p/32/4184_2.png) [@vm2p](https://discuss.ocaml.org/u/vm2p)\
**Post date:** [January 26, 2023, 12:06am UTC](https://discuss.ocaml.org/t/using-an-executable-as-library-in-dune/11249/1 "2023-01-26T00:06:32Z")

</div>

I’m building a project using dune and I’m facing the following situation. Essentially, my project depends on another project, not developed by me, from which I want to use some parts of the source code.

Here is more or less my project tree

```auto
my_project/
|---dune-project
|---src/
   |---dune
   |---extrenal-project/
      |---dune-project
      |---dune
      |---src/
         |---dune
   |---src-file.ml

```

The problem is that `external-project` has a `dune` file that builds it as an `executable`, instead of a `library`. Therefore, I cannot include it as a library in my `dune` file. Ideally, I don’t want to modify the `dune` file inside of `external-project`.

I’ve tried a series of combinations. Here is the current status of my `dune` file:

```auto
(dirs external-project)

(executable
 (name myexec)
 (libraries containers)
 (modules Myexec)
 (promote (until-clean) (into ".."))
)

(env (dev (flags (:standard -warn-error -A))))

```

Which allows me to compile `external-project` correctly, but then does not allow me to reference any of its files. I also tried `(dirs external-project external-project/src)` but to no success.

So, my question is: is there a way for me to reference `external-project` as a library, even though it is build as an `executable`?

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Khady](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/khady/32/469_2.png) [@Khady](https://discuss.ocaml.org/u/Khady)\
**Post date:** [January 26, 2023, 8:36am UTC](https://discuss.ocaml.org/t/using-an-executable-as-library-in-dune/11249/2 "2023-01-26T08:36:52Z")

</div>

dune has a `subdir` stanza which allows to modify/add dune rules in a directory without to modify files there. I think it was made exactly for cases like yours, with vendoring that shouldn’t be edited.

Reference at [Stanza Reference — Dune documentation](https://dune.readthedocs.io/en/stable/dune-files.html#subdir-1)
