This is supposedly fixed in recent OCaml versions (see http://caml.inria.fr/mantis/view.php?id=5763). Which version are you running?
Using Batteries in .mly file with ocamlbuild
-
24-06-2022 - |
Question
I have a project with OCaml .ml files and a Menhir .mly file. I use ocamlbuild to compile the project.
My _tags file contains this single line:
true: use_menhir, package(batteries)
Everything works well, except when I want to use Batteries in the .mly file. If I open Batteries ;;
between %{
and %}
in my .mly file, I get "Error: Unbound module Batteries" when calling ocamlbuild.
It seems that when ocamlbuild is calling menhir, like this:
/usr/bin/menhir --ocamlc '/usr/bin/ocamlfind ocamlc' --infer parser.mly
it forgets to add -package batteries
(or something equivalent) in the --ocamlc
option of menhir.
How can I fix that? Maybe a special rule for my .mly file in my _tags file could help? Or is it a ocamlbuild bug?
La solution
Autres conseils
Before the next OCaml release, there is a good work-around described in the link given by Jonathan. If your .mly
file is named foo.mly
, you can define a foo.mlypack
file with the following content:
Foo
Producing foo.ml
will then use the .mlypack
file (originally meant to support menhir's modular grammar combination feature), which will correctly pass the compilation options to the --infer
parameter -- because .mlypack
compilation was fixed long ago.