OCaml: How to include Base library?

I want to use the common Base library in a OCaml repl. I’ve installed it via opam in the shell:

opam install base

The installation seemingly was successful. When I try to re-install it, I get the following message:

[NOTE] Package base is already installed (current version is v0.15.1).

But adding it to a dune file

(library
 (name mylib)
 (libraries base))

and then trying to run the project results in

> dune build
File "lib/dune", line 3, characters 12-16:
3 |  (libraries base))
                ^^^^
Error: Library "base" not found.
-> required by library "mylib" in _build/default/lib
-> required by executable main in bin/dune:3
-> required by _build/default/bin/main.exe
-> required by alias bin/all
-> required by alias default
exit status 1 

Can somebody help me out, please?

Update:

I’ve just discovered that I can use Base if I run the dune build and dune exec ... commands on the command line. So how should I change the repl configuration such that the Run button does the same? The commands in the .replit file look exactly like the ones I’m using in the shell?

After learning a bit Nix, I finally found a working solution (at least so far no problems). Modifiying the Nix expression in the replit.nix file did the job:

{ pkgs }: {
  deps = [
    pkgs.ocaml
    pkgs.ocamlPackages.findlib   # <- New item
    pkgs.ocamlformat
    pkgs.opam
    pkgs.dune_3
    pkgs.ocamlPackages.utop
    pkgs.ocamlPackages.ocaml-lsp
    pkgs.ocamlPackages.base      # <- New item
  ];

  env = {
    CAML_LD_LIBRARY_PATH = "${pkgs.ocaml}/lib/ocaml/stublibs:${pkgs.ocaml}/lib/ocaml";
  };
}

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.