# Current state of ocamlnat

**URL:** <https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763>\
**Category:** Ecosystem\
**Created:** [May 13, 2020, 12:13pm UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763 "2020-05-13T12:13:34Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [May 13, 2020, 12:13pm UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/1 "2020-05-13T12:13:34Z")

</div>

I’ve been trying to use ocamlnat, the experimental native toplevel distributed with the compiler, but not installed by default. This is an attempt of a follow-up to [Interim report on experience with ocamlnat](https://discuss.ocaml.org/t/interim-report-on-experience-with-ocamlnat/833).

Following advice on discord, I created a fresh 4.10 switch and installed ocamlnat by doing `opam pin add ocaml-variants 4.10.0+flambda+no-flat-float-array --edit` and editing the opam file to include `make ocamlnat`, as explained in [the manual](https://caml.inria.fr/pub/docs/manual-ocaml/toplevel.html#s%3Aocamlnat). However, executing `ocamlnat` fails because no cmx file is found for `Topdirs`.

Does anyone have working installation instructions for ocamlnat? Is loading of libraries into ocamlnat still as cumbersome as in the thread mentioned above? Is it possible to build a version of utop that uses the native toplevel? Seemingly, a native REPL is not far away, but so far it does not seem to be usable?

---

<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:** [May 13, 2020, 5:41pm UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/2 "2020-05-13T17:41:15Z")

</div>

> [@n4323](#):
>
> However, executing `ocamlnat` fails because no cmx file is found for `Topdirs` .

I think you’ll need to provide more precise details, it may have been broken upstream since it’s not being tested in the CI (and will not be). I have an opam repo [over there](https://github.com/dbuenzli/opam-repo-ocamlnat) with a working ocamlnat (but for `4.07.1`).

As far as library loading is concerned many (but not all) of them can be loaded via [`omod`](https://erratique.ch/software/omod/doc/Omod.html#tutorial) and for line edition simply use `rlwrap` or [`Down`](https://erratique.ch/software/down/doc/index.html#quick_start).

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [May 14, 2020, 7:07am UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/3 "2020-05-14T07:07:24Z")

</div>

> [@dbuenzli](#):
>
> I think you’ll need to provide more precise details

Ok, thanks. Here is what I did. In a fresh switch of 4.10+flambda+no-flat-float-array, I opam pinned ocaml-variants and edited as described above. The additional make line in the opam file was  
`[make "-j%{jobs}%" {os != "cygwin"} "ocamlnat"]`.  
Installation seems to have worked since `ocamlnat` is available on the path after reinstalling. It also seems to be basically the same change to the opam file you were using?

Here is the output after typing `ocamlnat` at the command line:

```auto
OCaml version 4.10.0 - native toplevel

File "_none_", line 1:
Warning 58: no cmx file was found in path for module Topdirs, and its interface was not compiled with -opaque
>> Fatal error: Opttoploop.dll_run dlopen(/var/folders/bh/0mc1q9cn5ps48h60dygx_lhm00011n/T/camlTOP386c084.so, 10): Symbol not found: _camlTopdirs
  Referenced from: /var/folders/bh/0mc1q9cn5ps48h60dygx_lhm00011n/T/camlTOP386c084.so
  Expected in: flat namespace
 in /var/folders/bh/0mc1q9cn5ps48h60dygx_lhm00011n/T/camlTOP386c084.so
Fatal error: exception Misc.Fatal_error

```

---

<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:** [May 14, 2020, 7:34am UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/4 "2020-05-14T07:34:34Z")

</div>

I’ll have a look later but did you try to add `-I` options so that the missing `topdirs.cmx` gets into the search path ?

---

<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:** [May 14, 2020, 7:37am UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/5 "2020-05-14T07:37:18Z")

</div>

Mmmh actually that looks weird it should look for `Opttopdir`. I suspect you have stuff in your `.ocamlinit` that `ocamlnat` doesn’t like. Try to invoke `ocamlnat -noinit`

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [May 14, 2020, 7:38am UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/6 "2020-05-14T07:38:37Z")

</div>

Ah yes! I have this in the .ocamlinit :

```auto
(* Added by OPAM. *)
let () =
  try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
  with Not_found -> ()
;;

```

When I invoke `ocamlnat -noinit` I get a prompt!

---

<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:** [May 14, 2020, 7:39am UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/7 "2020-05-14T07:39:52Z")

</div>

Note that this bit should no longer be needed you can remove it from your `.ocamlinit`. In general at the moment though it’sdifficult to share your usual `.ocamlinit` with `ocamlnat`.

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [May 14, 2020, 7:50am UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/8 "2020-05-14T07:50:05Z")

</div>

Ok cool. I tried as a next step to install `ocamlfind` and invoke `#use "topfind";;` this fails with

```auto
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Topdirs, and its interface was not compiled with -opaque
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Toploop, and its interface was not compiled with -opaque
>> Fatal error: Opttoploop.dll_run dlopen(/var/folders/bh/0mc1q9cn5ps48h60dygx_lhm00011n/T/camlTOP5546fbf.so, 10): Symbol not found: _camlTopdirs
  Referenced from: /var/folders/bh/0mc1q9cn5ps48h60dygx_lhm00011n/T/camlTOP5546fbf.so
  Expected in: flat namespace
 in /var/folders/bh/0mc1q9cn5ps48h60dygx_lhm00011n/T/camlTOP5546fbf.so
Fatal error: exception Misc.Fatal_error

```

Is this just a problem with ocamlfind not installing a cmx or is it expected that findlib will not work? (in the latter case, it seems ocamlnat will be cumbersome to use)

---

<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:** [May 14, 2020, 7:58am UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/9 "2020-05-14T07:58:56Z")

</div>

`ocamlfind` will not work because it uses the bytecode toplevel API and a bit stupidly the ocamlnat API is separate despite providing the same functionality (see point 4. [here](https://github.com/ocaml/ocaml/issues/7589)).

As I said above use `omod` if you want to get to something (follow the tutorial I linked above). But not to anything unfortunately, report any loading issues you hit (some of which I’m already aware) on `omod`'s bug tracker.

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [May 14, 2020, 7:59am UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/10 "2020-05-14T07:59:14Z")

</div>

I just saw you posted omod as a solution for library loading. I tried it, and `#use "omod.nattop"` succeeds, however with the warning  
`Warning 58: no cmx file was found in path for module Opttopdirs, and its interface was not compiled with -opaque`. I tried to load `cmdliner` which succeeds.

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [May 14, 2020, 8:05am UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/11 "2020-05-14T08:05:37Z")

</div>

I’ll report any issues here or on the omod tracker.

A general question: How much work would it be if anyone decided to port utop to ocamlnat, disregarding the fact that the latter is experimental?

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [May 14, 2020, 8:21am UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/12 "2020-05-14T08:21:38Z")

</div>

Note that there is an ongoing project that aims to modernize/fix the native toplevel (incidentally it is spearheaded by the original author of `utop`), see [https://github.com/ocaml/RFCs/pull/15](https://github.com/ocaml/RFCs/pull/15).

Best wishes,  
Nicolás

---

<div class="post-metadata">

**Author:** ![BikalGurung](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bikalgurung/32/5105_2.png) [@BikalGurung](https://discuss.ocaml.org/u/BikalGurung)\
**Post date:** [May 14, 2020, 1:03pm UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/13 "2020-05-14T13:03:56Z")

</div>

I just came across this project [https://github.com/bmeurer/ocamlnat](https://github.com/bmeurer/ocamlnat) Is this the one ocaml currently has in distribution?

---

<div class="post-metadata">

**Author:** ![BikalGurung](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bikalgurung/32/5105_2.png) [@BikalGurung](https://discuss.ocaml.org/u/BikalGurung)\
**Post date:** [May 14, 2020, 1:11pm UTC](https://discuss.ocaml.org/t/current-state-of-ocamlnat/5763/14 "2020-05-14T13:11:18Z")

</div>

Answering myself, not it isn’t.
