Ocaml compile multiple files (circular dependencies)
I have downloaded xml-light
for ocaml and try to compile it, but it has never been succeeded, the problem is as follow.
When I in开发者_如何学Cput ocamlopt dtd.ml
, there will be an error Unbound module Xml
.
Then I input ocamlopt xml.ml
, there will be an error Unbound value XmlParser.make
.
Then I input ocamlopt xmlParser.ml
, there will be an error Unbound module Dtd
.
is there actually a way to compile them together? I feel so stupid because of this.
It is not so trivial, nothing surprising. Here is the output of make
(from mingw/cygwin ocaml distribution):
ocamlyacc xml_parser.mly
ocamlc xml.mli
ocamlc dtd.mli
ocamlc xml_parser.mli
ocamlc -c xml_parser.ml
ocamllex xml_lexer.mll
ocamlc xml_lexer.mli
ocamlc -c xml_lexer.ml
ocamlc -c dtd.ml
ocamlc xmlParser.mli
ocamlc -c xmlParser.ml
ocamlc -c xml.ml
ocamlc -o xml-light.cma -a xml_parser.cmo xml_lexer.cmo dtd.cmo xmlParser.cmo xml.cmo
And the test:
ocamlc xml-light.cma test.ml -o test.exe
make install
output:
ocamlopt -c xml_parser.ml
ocamlopt -c xml_lexer.ml
ocamlopt -c dtd.ml
ocamlopt -c xmlParser.ml
ocamlopt -c xml.ml
ocamlopt -o xml-light.cmxa -a xml_parser.cmx xml_lexer.cmx dtd.cmx xmlParser.cmx xml.cmx
cp xml-light.cmxa xml-light.a xml-light.cma xml.mli xmlParser.mli dtd.mli xml.cmi xmlParser.cmi dtd.cmi xml.cmx dtd.cmx xmlParser.cmx `ocamlc -where`
Note the last line (i've separated it with newline): you probably won't have cp command; just create %OCAMLLIB%\xml-light
directory manually and copy listed files there. Then you can build your project like this:
ocamlopt -I +xml-light xml-light.cmxa foo.ml -o foo.exe
精彩评论