# Building the Llvm tutorial with dune

**URL:** <https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944>\
**Category:** Learning\
**Tags:** ocamlbuild, llvm, jbuilder, build, dune\
**Created:** [November 22, 2018, 6:06pm UTC](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944 "2018-11-22T18:06:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![abk](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/abk/32/1016_2.png) [@abk](https://discuss.ocaml.org/u/abk)\
**Post date:** [November 22, 2018, 6:06pm UTC](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944/1 "2018-11-22T18:06:10Z")

</div>

Hi everyone,  
I was trying to go through the LLVM OCaml tutorial [here](https://llvm.org/docs/tutorial/OCamlLangImpl1.html), but I wanted to build it using dune instead of ocamlbuild as is done in the tutorial. The error I’m getting is that there is no implementation for Llvm\_analysis:

```auto
Error: No implementations provided for the following modules:
         Llvm_analysis referenced from lib/kaleidoscope_lib.cmxa(Kaleidoscope_lib__Codegen)

```

Any suggestions on how to fix this?

Here is the dune file for my lib:

```auto
(library
 (name kaleidoscope_lib)
 (libraries 
   angstrom
   async
   core
   llvm)
 (preprocess (pps ppx_jane ppx_expect ppx_let))
 (inline_tests))

```

If I delete all the uses of Llvm\_analysis, but leave in the uses of Llvm, then everything builds fine.

I can also see the files `llvm_analysis.cmi`, `llvm_analysis.cmx`, and `lllvm_analysis.mli` in `~/.opam/4.06.0/lib/llvm`, as well as `llvm_analysis.a`, `llvm_analysis.cma`, and `llvm_analysis.cmxa` in `~/.opam/4.06.0/lib/llvm/shared`, so I don’t think anything’s missing.

For reference, this is the [build setup from the tutorial](https://llvm.org/docs/tutorial/OCamlLangImpl3.html#full-code-listing) (note that I’m using `angstrom` for my parser instead of `camlp4`):

\_tags:

```ocaml
<{lexer,parser}.ml>: use_camlp4, pp(camlp4of)
<*.{byte,native}>: g++, use_llvm, use_llvm_analysis

```

myocamlbuild.ml:

```ocaml
(* myocamlbuild.ml *)
open Ocamlbuild_plugin;;

ocaml_lib ~extern:true "llvm";;
ocaml_lib ~extern:true "llvm_analysis";;

flag ["link"; "ocaml"; "g++"] (S[A"-cc"; A"g++"]);; 

```

---

<div class="post-metadata">

**Author:** ![mseri](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mseri/32/91_2.png) [@mseri](https://discuss.ocaml.org/u/mseri)\
**Post date:** [November 22, 2018, 7:04pm UTC](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944/2 "2018-11-22T19:04:19Z")

</div>

What happens if you add `llvm_analysis` in the list of libraries in the dune file?

---

<div class="post-metadata">

**Author:** ![abk](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/abk/32/1016_2.png) [@abk](https://discuss.ocaml.org/u/abk)\
**Post date:** [November 22, 2018, 7:39pm UTC](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944/3 "2018-11-22T19:39:19Z")

</div>

It can’t find the library (it’s not an opam package, just a module in the llvm package).

```auto
File "lib/dune", line 8, characters 3-16:
8 | llvm_analysis)
       ^^^^^^^^^^^^^
Error: Library "llvm_analysis" not found.
Hint: try: dune external-lib-deps --missing lib/.utop/utop.exe

```

I also checked out `dune rules` which has several references to `llvm/shared/llvm.cmxa`, but not `llvm/shared/llvm_analysis.cmxa`.

---

<div class="post-metadata">

**Author:** ![rgrinberg](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rgrinberg/32/40_2.png) [@rgrinberg](https://discuss.ocaml.org/u/rgrinberg)\
**Post date:** [November 22, 2018, 8:04pm UTC](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944/4 "2018-11-22T20:04:48Z")

</div>

Could you post the META file for the llvm library? It will be located in `$ ocamlfind query llvm`. Also, what is the output of `$ ocamlfind list | grep -i llvm`? It’s strange that llvm\_analysis is not found and yet the ocamlbuild build sees it.

Anyway, my guess is that the problem lies in the META file of the llvm package.

---

<div class="post-metadata">

**Author:** ![zshipko](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zshipko/32/233_2.png) [@zshipko](https://discuss.ocaml.org/u/zshipko)\
**Post date:** [November 22, 2018, 8:16pm UTC](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944/5 "2018-11-22T20:16:50Z")

</div>

I believe you use `llvm.analysis` rather than `llvm_analysis` in your dune file. I can’t confirm this right now, so apologies if I’m mis-remembering.

---

<div class="post-metadata">

**Author:** ![abk](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/abk/32/1016_2.png) [@abk](https://discuss.ocaml.org/u/abk)\
**Post date:** [November 23, 2018, 2:22pm UTC](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944/6 "2018-11-23T14:22:36Z")

</div>

Continuing the discussion from [Building the Llvm tutorial with dune](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944/5):

> [@rgrinberg](#):
>
> Could you post the META file for the llvm library?

`ocamlfind query llvm` returns `~/.opam/4.06.0/lib/llvm` which has no META file:

```auto
$ ls -I *.a -I *.mli -I *.cmi -I *.cmx ~/.opam/4.06.0/lib/llvm
opam.config
shared
static

```

(also note that opam.config is empty).

> [@rgrinberg](#):
>
> Also, what is the output of `$ ocamlfind list | grep -i llvm`? It’s strange that llvm\_analysis is not found and yet the ocamlbuild build sees it.

```auto
$ ocamlfind list | grep -i llvm
llvm (version: 6.0.0)
llvm.all_backends (version: 6.0.0)
llvm.analysis (version: 6.0.0)
llvm.bitreader (version: 6.0.0)
llvm.bitwriter (version: 6.0.0)
llvm.executionengine (version: 6.0.0)
llvm.ipo (version: 6.0.0)
llvm.irreader (version: 6.0.0)
llvm.linker (version: 6.0.0)
llvm.passmgr_builder (version: 6.0.0)
llvm.scalar_opts (version: 6.0.0)
llvm.target (version: 6.0.0)
llvm.transform_utils (version: 6.0.0)
llvm.vectorize (version: 6.0.0)
llvm_AArch64 (version: 6.0.0)
llvm_AMDGPU (version: 6.0.0)
llvm_ARM (version: 6.0.0)
llvm_BPF (version: 6.0.0)
llvm_Hexagon (version: 6.0.0)
llvm_Lanai (version: 6.0.0)
llvm_MSP430 (version: 6.0.0)
llvm_Mips (version: 6.0.0)
llvm_NVPTX (version: 6.0.0)
llvm_PowerPC (version: 6.0.0)
llvm_Sparc (version: 6.0.0)
llvm_SystemZ (version: 6.0.0)
llvm_X86 (version: 6.0.0)
llvm_XCore (version: 6.0.0)

```

So that lists `llvm.analysis` as @zshipko mentioned. Also I should mention that I didn’t actually check that the ocamlbuild setup works, so maybe it has the same problem. Thanks for all the suggestions.

---

<div class="post-metadata">

**Author:** ![abk](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/abk/32/1016_2.png) [@abk](https://discuss.ocaml.org/u/abk)\
**Post date:** [November 23, 2018, 2:23pm UTC](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944/7 "2018-11-23T14:23:30Z")

</div>

> [@zshipko](#):
>
> I believe you use `llvm.analysis` rather than `llvm_analysis` in your dune file.

Yes that worked. Thanks for the help.

---

<div class="post-metadata">

**Author:** ![jeremiedimino](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jeremiedimino/32/699_2.png) [@jeremiedimino](https://discuss.ocaml.org/u/jeremiedimino)\
**Post date:** [November 26, 2018, 8:41am UTC](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944/8 "2018-11-26T08:41:35Z")

</div>

BTW, last time I checked llvm used the old META file layout, so its META file was `META.llvm` in the library directory rather than `llvm/META`

---

<div class="post-metadata">

**Author:** ![perry](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/perry/32/518_2.png) [@perry](https://discuss.ocaml.org/u/perry)\
**Post date:** [November 26, 2018, 1:50pm UTC](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944/9 "2018-11-26T13:50:24Z")

</div>

On a wider note, the LLVM tutorial is based on very old OCaml features. It uses camlp4 for example. It probably should be updated by someone.

---

<div class="post-metadata">

**Author:** ![abk](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/abk/32/1016_2.png) [@abk](https://discuss.ocaml.org/u/abk)\
**Post date:** [November 29, 2018, 2:45am UTC](https://discuss.ocaml.org/t/building-the-llvm-tutorial-with-dune/2944/10 "2018-11-29T02:45:23Z")

</div>

Ah yes, `META.llvm` is in lib directory. In addition to using old OCaml features, the tutorial also seems to be based on outdated LLVM as well.
