# Fmt module usage

**URL:** <https://discuss.ocaml.org/t/fmt-module-usage/4161>\
**Category:** Learning\
**Created:** [July 28, 2019, 12:03pm UTC](https://discuss.ocaml.org/t/fmt-module-usage/4161 "2019-07-28T12:03:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Konrad\_Eisele](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/konrad_eisele/32/1708_2.png) [@Konrad\_Eisele](https://discuss.ocaml.org/u/Konrad_Eisele)\
**Post date:** [July 28, 2019, 12:03pm UTC](https://discuss.ocaml.org/t/fmt-module-usage/4161/1 "2019-07-28T12:03:37Z")

</div>

I’m trying to learn ocaml and wanted to see weather I could get printing of data structures working and run into a problem:  
I saw that there is a module called Fmt ([https://github.com/dbuenzli/fmt](https://github.com/dbuenzli/fmt)) and installed it via “opam install fmt”. Inside “ocaml” I can do a “#require “fmt”” . However I cannot use the library with “ocamlc” and “open Fmt;;” . Is the Fmt module only used for the interactive ocaml ?

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [July 28, 2019, 12:20pm UTC](https://discuss.ocaml.org/t/fmt-module-usage/4161/2 "2019-07-28T12:20:30Z")

</div>

You should be able to compile you source with:

```
ocamlfind ocamlc -c -package fmt mysource.ml

```

If you want to compile things directly with `ocamlc` and use libraries installed via `opam`, see [this tutorial](https://ocaml.org/learn/tutorials/compiling_ocaml_projects.html).

(Also you should not `open Fmt` it’s bad style, use qualified names e.g. `Fmt.string`).

---

<div class="post-metadata">

**Author:** ![vrotaru](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vrotaru/32/39_2.png) [@vrotaru](https://discuss.ocaml.org/u/vrotaru)\
**Post date:** [July 28, 2019, 12:25pm UTC](https://discuss.ocaml.org/t/fmt-module-usage/4161/3 "2019-07-28T12:25:01Z")

</div>

```auto
> a.ml echo 'open Fmt'
ocamlc -c a.ml

```

This fails with

```auto
Error: Unbound module Fmt

```

This works

```auto
ocamlc -I $(opam var lib)/fmt -c a.ml

```

I suggest you invest some time in learning the basics of `dune`. But, I guess it depends on what works for you

---

<div class="post-metadata">

**Author:** ![Konrad\_Eisele](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/konrad_eisele/32/1708_2.png) [@Konrad\_Eisele](https://discuss.ocaml.org/u/Konrad_Eisele)\
**Post date:** [July 28, 2019, 12:49pm UTC](https://discuss.ocaml.org/t/fmt-module-usage/4161/4 "2019-07-28T12:49:29Z")

</div>

I’m using (m.ml):

```
let () =
  let str u = Format.asprintf "%a" Fmt.Dump.uchar u in
  Printf.printf "%s\n" (str Uchar.min)
;;

```

I want to compile it to a binary that I can execute. How is the command to achieve this? The above command uses `-c`, so I guess it only compiles an object file. However how can I then link it? I thought I could use `ocamlfind ocamlc -package fmt m.ml` and get a.out but it just returns silently.

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [July 28, 2019, 12:52pm UTC](https://discuss.ocaml.org/t/fmt-module-usage/4161/5 "2019-07-28T12:52:51Z")

</div>

> [@Konrad\_Eisele](#):
>
> could use `ocamlfind ocamlc -package fmt m.ml` and get a.out but it just returns silently.

I’m wondering about the “silently” you should get a link error but this should do it:

```auto
> ocamlfind ocamlc -linkpkg -package fmt m.ml
> ./a.out
U+0000

```

---

<div class="post-metadata">

**Author:** ![Konrad\_Eisele](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/konrad_eisele/32/1708_2.png) [@Konrad\_Eisele](https://discuss.ocaml.org/u/Konrad_Eisele)\
**Post date:** [July 28, 2019, 1:09pm UTC](https://discuss.ocaml.org/t/fmt-module-usage/4161/6 "2019-07-28T13:09:07Z")

</div>

That made it work : `-linkpkg` Thanks. I have another question about howto use Fmt to print i.e. Lists but I open open thread.

---

<div class="post-metadata">

**Author:** ![atzensepp](https://avatars.discourse-cdn.com/v4/letter/a/e19adc/32.png) [@atzensepp](https://discuss.ocaml.org/u/atzensepp)\
**Post date:** [July 28, 2019, 3:21pm UTC](https://discuss.ocaml.org/t/fmt-module-usage/4161/7 "2019-07-28T15:21:06Z")

</div>

For each module installed with opam a directory is created under $(opam var lib).  
Is there no easier way instead to provide all the install directories for each module to be included?

---

<div class="post-metadata">

**Author:** ![vrotaru](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vrotaru/32/39_2.png) [@vrotaru](https://discuss.ocaml.org/u/vrotaru)\
**Post date:** [July 28, 2019, 5:44pm UTC](https://discuss.ocaml.org/t/fmt-module-usage/4161/8 "2019-07-28T17:44:49Z")

</div>

Don’t think so. You can put all in a big shared directory, but how will you defend against Library A overwriting files of Library B?

And that’s why people use build systems.
