# Trying to get Cacti example working

**URL:** <https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790>\
**Category:** Learning\
**Tags:** caqti, dune\
**Created:** [March 25, 2023, 8:24pm UTC](https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790 "2023-03-25T20:24:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![garyrob](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@garyrob](https://discuss.ocaml.org/u/garyrob)\
**Post date:** [March 25, 2023, 8:24pm UTC](https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790/1 "2023-03-25T20:24:37Z")

</div>

I am extremely frustrated and hoping someone can help me. I am trying to get the [example code in the Caqti github](https://github.com/paurkedal/ocaml-caqti/tree/master/examples) working working. It’s for a project they call bikereg.

Here are the steps I take:

```auto
dune init proj bikereg
cd bikereg

```

Then I replace bin/dune with the version in the examples directory mentioned above. It contains:

```auto
(executable
 (name bikereg)
 (modules bikereg)
 (libraries caqti caqti-dynload caqti-lwt caqti-lwt.unix testlib))

(rule
 (alias runtest)
 (package caqti-lwt)
 (deps (:test bikereg.exe) (alias ../testsuite/drivers) ../testsuite/uris.conf)
 (locks /db/bikereg)
 (action
  (setenv OCAMLPATH ../testsuite
   (run %{test} -U ../testsuite/uris.conf))))

```

Then I edit `dune-project` to depend on the libraries mentioned in the dune file. After editing, the package section reads:

```auto
(package
 (name bikereg)
 (synopsis "A short synopsis")
 (description "A longer description")
 (depends ocaml dune caqti caqti-dynload caqti-lwt caqti-lwt.unix testlib)
 (tags
  (topics "to describe" your project)))

```

Finally I run:  
`dune build`

I get the output:

```auto
Error: The current scope doesn't define package "caqti-lwt".
The only packages for which you can declare elements to be installed in this
directory are:
- bikereg (because of bikereg.opam)

```

I’ve tried editing bikereg.opam to fix the problem, but it doesn’t help. Moreover the [OCaml Quickstart](http://ocamlverse.net/content/quickstart_ocaml_project_dune.html) says “Do not update project\_name.opam manually! Let dune do it for you.” and says that we should use `dune build` to do that.

I have no idea what to do now to move forward. Perhaps the Caqti example is just wrong and shouldn’t be referring to caqti-lwt? But caqti-lwt does appear in the github directory for Caqti, so apparently it does exist. I don’t know why there would be a problem in referring to it.

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [March 25, 2023, 8:59pm UTC](https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790/2 "2023-03-25T20:59:53Z")

</div>

> [@garyrob](#):
>
> `caqti-lwt.unix`

Just a quick note that the convention is `package.sublibrary`, so you would only have a single `depends ... package ...`, not `depends ... package package.sublibrary ...` as above. But I don’t know anything about `caqti`.

---

<div class="post-metadata">

**Author:** ![Frederic\_Loyer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/frederic_loyer/32/3472_2.png) [@Frederic\_Loyer](https://discuss.ocaml.org/u/Frederic_Loyer)\
**Post date:** [March 25, 2023, 9:14pm UTC](https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790/3 "2023-03-25T21:14:06Z")

</div>

I guess `caqti-lwt` should be install with `opam` (and its drivers too).

---

<div class="post-metadata">

**Author:** ![garyrob](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@garyrob](https://discuss.ocaml.org/u/garyrob)\
**Post date:** [March 25, 2023, 9:20pm UTC](https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790/4 "2023-03-25T21:20:50Z")

</div>

Hi Frederic, thanks for replying. I tried a manual  
`opam install caqti-lwt`  
and it installed without errors, including dependencies.

I then tried again to do  
`dune build`

and got the same response as before:  
File “bin/dune”, line 8, characters 10-19:

```auto
8 | (package caqti-lwt)
              ^^^^^^^^^
Error: The current scope doesn't define package "caqti-lwt".
The only packages for which you can declare elements to be installed in this
directory are:
- bikereg (because of bikereg.opam)

```

This is really frustrating!

---

<div class="post-metadata">

**Author:** ![garyrob](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@garyrob](https://discuss.ocaml.org/u/garyrob)\
**Post date:** [March 25, 2023, 9:24pm UTC](https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790/5 "2023-03-25T21:24:28Z")

</div>

Hi lukstaff, thank you for replying… I removed the qaqti-lwt.unix entries in both the bin/dune and dune-project file, and got exactly the same result.

---

<div class="post-metadata">

**Author:** ![patricoferris](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/patricoferris/32/3621_2.png) [@patricoferris](https://discuss.ocaml.org/u/patricoferris)\
**Post date:** [March 25, 2023, 9:32pm UTC](https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790/6 "2023-03-25T21:32:45Z")

</div>

I think the problem is the `(package caqti-lwt)` in the `rule` for the test that runs the `bikereg` executable. This is telling dune that _that_ specific test should be attached to the package `caqti-lwt` which makes sense in the `caqti` repository where that package is defined, but won’t work outside of it.

I think you just need to remove that line from that dune stanza. However, there are other bits in it that stanza that reference that repository too like the `../testsuite` so it might just be better to remove the test stanza entirely and build the executable and run it yourself (you’ll need to change bikereg a bit and manually run the database, or try to copy the testsuite setup from the original repo)?

---

<div class="post-metadata">

**Author:** ![garyrob](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@garyrob](https://discuss.ocaml.org/u/garyrob)\
**Post date:** [March 26, 2023, 1:20am UTC](https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790/8 "2023-03-26T01:20:03Z")

</div>

patriocoferris: Thank you!!! I think you’re right. I’ll post here again when I get something working.

---

<div class="post-metadata">

**Author:** ![benjamin-thomas](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/benjamin-thomas/32/3966_2.png) [@benjamin-thomas](https://discuss.ocaml.org/u/benjamin-thomas)\
**Post date:** [March 26, 2023, 5:53am UTC](https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790/9 "2023-03-26T05:53:55Z")

</div>

I’ve played with caqti a few months ago.

Maybe having a look at this project setup would help?

> **[multi-playground/db/ocaml/caqti at 6941425b6c8d5f26d386899fbc110efb1c98a1b0 ·...](https://github.com/benjamin-thomas/multi-playground/tree/6941425b6c8d5f26d386899fbc110efb1c98a1b0/db/ocaml/caqti)**
>
> 6941425b6c8d5f26d386899fbc110efb1c98a1b0/db/ocaml/caqti

---

<div class="post-metadata">

**Author:** ![garyrob](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@garyrob](https://discuss.ocaml.org/u/garyrob)\
**Post date:** [March 29, 2023, 11:26pm UTC](https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790/10 "2023-03-29T23:26:27Z")

</div>

Thanks Benjamin! I’ll have a look.

---

<div class="post-metadata">

**Author:** ![paurkedal](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/paurkedal/32/586_2.png) [@paurkedal](https://discuss.ocaml.org/u/paurkedal)\
**Post date:** [April 4, 2023, 8:15pm UTC](https://discuss.ocaml.org/t/trying-to-get-cacti-example-working/11790/11 "2023-04-04T20:15:29Z")

</div>

To elaborate on the second point, the only purpose of the reference to `../testsuite` is to make the `META` files of the driver available for dynamic loading. When building the example separately from the rest of the package, it can be removed, assuming the libraries are installed in the OPAM switch.
