# Dune + ocamldebug

**URL:** <https://discuss.ocaml.org/t/dune-ocamldebug/9850>\
**Category:** Learning\
**Tags:** debugging, dune\
**Created:** [May 14, 2022, 6:07am UTC](https://discuss.ocaml.org/t/dune-ocamldebug/9850 "2022-05-14T06:07:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vdolgov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vdolgov/32/3430_2.png) [@vdolgov](https://discuss.ocaml.org/u/vdolgov)\
**Post date:** [May 14, 2022, 6:07am UTC](https://discuss.ocaml.org/t/dune-ocamldebug/9850/1 "2022-05-14T06:07:59Z")

</div>

I’m trying to figure out how to use `ocamldebug`, although it seems quite easy on the wiki, I find it difficult to apply it to an actual `dune` project.

For example, I made a project with `dune init proj hello` and added `(modes byte)` to `bin/dune`, then I modified sources to bring dependency on  
internal library:

```ocaml
(* lib/hello.ml *)

let greeting = "Hello"

```

```ocaml
(* bin/main.ml *)

open Hello

let () =
  let message = greeting ^ ", World!" in
  print_endline message

```

Next, I launch debugger and see that it cannot find library:

```nohighlight
$ ocamldebug _build/default/bin/main.bc

(ocd) break @ Dune __exe__ Main 5
...

(ocd) r
Time: 21 - pc: 0:11272 - module Dune __exe__ Main
Breakpoint: 1
5 <|b|>print_endline message

(ocd) p message
Cannot find module Hello.

```

so I fixed this with include

```nohighlight
$ ocamldebug -I _build/default/lib/.hello.objs/byte/ _build/default/bin/main.bc 

...

(ocd) p message
message: string = "Hello, World!"

```

But it doesn’t feel right to me, as I need to include manually every library that a project uses, and paths to them are not obvious.

Two questions:

1. Is there a way to include all libraries of a project?
2. Also `ocamldebug` manual states that everything should be compiled with `-g` flag, do I need to add it to all `dune` project files?

---

<div class="post-metadata">

**Author:** ![Muqiu-Han](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/muqiu-han/32/5696_2.png) [@Muqiu-Han](https://discuss.ocaml.org/u/Muqiu-Han)\
**Post date:** [May 14, 2022, 10:06am UTC](https://discuss.ocaml.org/t/dune-ocamldebug/9850/2 "2022-05-14T10:06:27Z")

</div>

> [@vdolgov](#):
>
> Also `ocamldebug` manual states that everything should be compiled with `-g` flag, do I need to add it to all `dune` project files?

dune will add `-g` flag for you by default
