Unbound module ANSITerminal

Trying to test the ANSITerminal module and installed it on my windows box.

PS H:\Ocaml\Bataille> opam install ANSITerminal

Then in Bataille.ml:

open ANSITerminal;;

within my dune project … followed by :

PS H:\Ocaml\Bataille> dune build
File "bin/Bataille.ml", line 4, characters 5-17:
4 | open ANSITerminal;;
Error: Unbound module ANSITerminal

Yet another unbound module this time. No issue with other modules though : Printf, Random, List, …

Help appreciated from the gurus .


You need to specify that you want to use the ANSITerminal library in your dune file, see for example here (substitute lwt.unix by ANSITerminal).

The other modules you mention are part of the standard library against which your program is linked by default so there’s no need to specify anything to use them.


Thanks, it worked and welcomed me with a generous :

PS H:\OCaml\Bataille> dune build
File "bin/dune", line 4, characters 21-33:
4 |  (libraries Bataille ANSITerminal))
Error: Library "ANSITerminal" not found.

If I could avoid trying to look for the module path to fill it to dune … I would avoid though I am not sure dune sees it this way.

1 Like

You will need to put the module in your dune-project file as well at the root of your workspace as well if you haven’t already.

That dune-project file should should have a stanza similar to the one below, and you will need to include whatever libraries you declare in the (depends ...) clause.

 (name placeholder)
 (synopsis "A short synopsis")
 (description "A longer description")
 (depends ocaml dune raylib)
  (topics "to describe" your project)))

Edit: never mind. @nojb corrected me on this misconception below.

You need to make sure that the ANSITerminal library is installed: opam install ANSITerminal.

Actually, the (package) stanza is not used in any way for compilation; it is only relevant when you want to publish your package, so it is not relevant here.



(Just a 2¢ for newcomers.)

But there’s an idiom: opam install . --deps-only: it makes sense to put the library in the package dependencies and not use opam install X for specific dependencies X, to make one’s life easier when changing switches (and ultimately when making the project public).


But it should be mentioned that before doing that, you probably want to create a local switch first: opam switch create --no-install .

1 Like

This had been done already though, as stated in my initial post.

PS H:\OCaml\Bataille> opam info ANSITerminal

<><> ANSITerminal: information on all versions ><><><><><><><><><><><><><><><><>
name                   ANSITerminal
all-installed-versions 0.8.5 [playground]
all-versions           0.6  0.6.2  0.6.3  0.6.4  0.6.5  0.7  0.8  0.8.1  0.8.2  0.8.3  0.8.4  0.8.5

<><> Version-specific details <><><><><><><><><><><><><><><><><><><><><><><><><>
version      0.8.5
repository   fdopen-mingw-1.2.0-4.14.0
pin          https://github.com/Chris00/ANSITerminal/releases/download/0.8.5/ANSITerminal-0.8.5.tbz
url.src      "https://github.com/Chris00/ANSITerminal/releases/download/0.8.5/ANSITerminal-0.8.5.tbz"
url.checksum "sha256=ab73b218b6a30267d2bbc43312dcf313981b8b0bec555d92b06b87664b2dd30e"
homepage     "https://github.com/Chris00/ANSITerminal"
doc          "https://Chris00.github.io/ANSITerminal/doc"
bug-reports  "https://github.com/Chris00/ANSITerminal/issues"
dev-repo     "git+https://github.com/Chris00/ANSITerminal.git"
authors      "Christophe Troestler" "Vincent Hugot"
maintainer   "Christophe Troestler <Christophe.Troestler@umons.ac.be>"
license      "LGPL-3.0-or-later WITH OCaml-LGPL-linking-exception"
tags         "terminal"
depends      "ocaml" {os != "win32" | >= "4.04"}
             "dune" {>= "2.0"}
synopsis     Basic control of ANSI compliant terminals and the windows shell
description  ANSITerminal is a module allowing to use the colors and cursor
             movements on ANSI terminals. It also works on the windows shell (but
             this part is currently work in progress).

In that case, have you checked if your environment is in sync with your current OPAM switch? OPAM will tell you if you do opam switch. If it is not, Installing OCaml · OCaml Documentation suggests doing

PS H:\OCaml\Bataille> (& opam env) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ }

to get it in sync (under PowerShell).


Indeed, my “switch” was not in “sync” … Looks like I can talk ocaml now.
Thanks @nojb