'Could not find the .cmi file
I would like to add a makefile for this project. I tried the following makefile:
SHELL:= /bin/bash
OCAMLC= ocamlfind ocamlc -package ppx_deriving.std -package sedlex.ppx -package sedlex -package MenhirLib
OCAMLYACC= $(OCAMLPREFIX)menhir -v
OCAMLLEX= $(OCAMLPREFIX)ocamllex -ml
%.ml %.mli: %.mly
$(OCAMLYACC) $*.mly
%.ml: %.mll
$(OCAMLLEX) $*.mll
%.cmi: %.mli
$(OCAMLC) $(OCAMLFLAGS) -c $*.ml
%.cmo: %.ml
$(OCAMLC) $(OCAMLFLAGS) -c $*.ml
ML_DOMAIN_MAIN= syntax.ml \
parser.ml \
lexer.ml \
calc.ml
CMO_DOMAIN_MAIN=$(ML_DOMAIN_MAIN:%.ml=%.cmo)
calc: $(CMO_DOMAIN_MAIN)
$(OCAMLC) -g -linkpkg -o $@ $+
clean:
rm -rf calc *.o *.cm[oixa] *.annot *~ *.log *.output *.out *.mli parser.ml parser.mli
It returned an error:
menhir -v parser.mly
ocamlfind ocamlc -package ppx_deriving.std -package sedlex.ppx -package sedlex -package MenhirLib -c parser.ml
File "parser.ml", line 1:
Error: Could not find the .cmi file for interface parser.mli.
make: *** [parser.cmo] Error 2
rm parser.ml
Does anyone know how to fix this?
Solution 1:[1]
You have a typo in this rule:
%.cmi: %.mli
$(OCAMLC) $(OCAMLFLAGS) -c $*.ml
The prerequisite is .mli but you pass .ml to the compiler.
Why don't you just use the $< automatic variable, then you don't have to worry about this?
%.ml %.mli: %.mly
$(OCAMLYACC) $<
%.ml: %.mll
$(OCAMLLEX) $<
%.cmi: %.mli
$(OCAMLC) $(OCAMLFLAGS) -c $<
%.cmo: %.ml
$(OCAMLC) $(OCAMLFLAGS) -c $<
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MadScientist |
