"Module is unavailable" error, when using new -I +str syntax [SOLVED]

I recently switched from a <5 OCaml compiler to a 5.1.1 version.
I therefore need to take the following warning from ocamlc into account :

File "_none_", line 1:
Alert ocaml_deprecated_auto_include: 
OCaml's lib directory layout changed in 5.0. The str subdirectory has been
automatically added to the search path, but you should add -I +str to the
command-line to silence this alert (e.g. by adding str to the list of
libraries in your dune file, or adding use_str to your _tags file for
ocamlbuild, or using -package str for ocamlfind).

To consider a minimal example, suppose we have just one file using_str.ml
which contains just the line let bs = Str.bounded_split ;;

My naive try at the new syntax works with partial, separate compilation (with the “-c” option)
but not with full compilation (without the “-c” option) :

$ls
using_str.ml
$ocamlc -I +str -c using_str.ml
$ls
using_str.cmi  using_str.cmo  using_str.ml
$ocamlc -I +str  using_str.ml
File "using_str.ml", line 1:
Error: Module `Str' is unavailable (required by `Using_str')

What is the correct syntax for the second call to ocamlc ?

Unless I missed something, this error “Module (…) is unavailable” is not documented
in the OCaml manual. Section 13.4 only lists the most common errors which do not include this one.

When linking, you need to provide the archives of the linked libraries:

$ ocamlc -I +str -c using_str.ml
$ ocamlc -I +str str.cma using_str.cmo -o using_str

or in one command:

$ ocamlc -I +str str.cma using_str.ml -o using_str
1 Like