# Very basic dune question

**URL:** <https://discuss.ocaml.org/t/very-basic-dune-question/5129>\
**Category:** Ecosystem\
**Tags:** dune\
**Created:** [February 5, 2020, 3:01pm UTC](https://discuss.ocaml.org/t/very-basic-dune-question/5129 "2020-02-05T15:01:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![threepwood](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@threepwood](https://discuss.ocaml.org/u/threepwood)\
**Post date:** [February 5, 2020, 3:01pm UTC](https://discuss.ocaml.org/t/very-basic-dune-question/5129/1 "2020-02-05T15:01:29Z")

</div>

Hi, sorry for the basic question but I’m having a very hard time finding my way through the dune documentation. From time to time I write a one-file binary to process corpus data for scientific purposes. This time I decided to compile it with dune so it’s easier to make it grow later, and I would like dune to take care of making it available to me in an easy way, without having to care about what’s in `_build`.

Ideally, I would want a way of making dune put the executable, without a `.exe` extension, in an arbitrary place on my system (such as `/home/myname/.local/bin/`). Otherwise I would settle for having it in the root directory of my project so I can conveniently put it where I want. Can these things be done?

I had a look at the `rule` stanza but it seems to require a file as target name (there is no sense in which this applies here). I also tried the install stanza with `misc` as section but then dune complains about the lack of `.opam` file (at any rate the documentation for `misc` does not clearly say what it does, it looks like you’re not supposed to use it).

---

<div class="post-metadata">

**Author:** ![keleshev](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/keleshev/32/3779_2.png) [@keleshev](https://discuss.ocaml.org/u/keleshev)\
**Post date:** [February 5, 2020, 8:10pm UTC](https://discuss.ocaml.org/t/very-basic-dune-question/5129/2 "2020-02-05T20:10:32Z")

</div>

Here’s a small gist I’ve made:

> <https://gist.github.com/keleshev/17765cb0b81557e03d27fc4a4b91fcec>
>
> There are more than three files. show original

You’ve got a hello-world program `my_program.ml`, a `dune` file:

```auto
(executable
 (public_name my_program))

```

As well as a `dune-project` file (which is auto-generated, but it’s a good idea to commit it), and an empty `my_program.opam` file. And the last one is the key to making an installable package. That’s the convention, for dune to know that the public artifacts are installable.

With this you can do `dune build && dune install` and it will install it by default into the current opam switch. However you can pass `--prefix=./local` to install it into an alternative directory.

In the gist I’ve included an example `Makefile` that allows you to do the standard-ish `make PREFIX=./local install`.

---

<div class="post-metadata">

**Author:** ![threepwood](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@threepwood](https://discuss.ocaml.org/u/threepwood)\
**Post date:** [February 6, 2020, 1:41pm UTC](https://discuss.ocaml.org/t/very-basic-dune-question/5129/3 "2020-02-06T13:41:24Z")

</div>

Thanks a lot for your answer. So it looks like what I was missing was the empty `.opam` file.

I’m still not super satisfied with the result because it installs some metadata I don’t care about under `/lib`. Is there a way to not have that?

(Other than that, I have to say, this looks like a lot of “bureaucracy” to me. I would have hoped it was possible to use dune while ignoring opam and the notion of package entirely.)

---

<div class="post-metadata">

**Author:** ![keleshev](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/keleshev/32/3779_2.png) [@keleshev](https://discuss.ocaml.org/u/keleshev)\
**Post date:** [February 6, 2020, 9:30pm UTC](https://discuss.ocaml.org/t/very-basic-dune-question/5129/4 "2020-02-06T21:30:14Z")

</div>

Don’t know how to ignore the `lib` metadata, unfortunately. I agree with your critique, the need for an `.opam` file tripped me up as well the first time I needed it. But I must say that things are improving. It used to be that you had to run `dune build @install` and that was a gotcha for many (including me), but now you can just `dune build`.
