我已阅读this question等, 但我的编译问题尚未解决。OCaml模块的单独编译
我测试单独的编译与这些文件:
testmoda.ml
module Testmoda = struct
let greeter() = print_endline "greetings from module a"
end
testmodb.ml
module Testmodb = struct
let dogreet() = print_endline "Modul B:"; Testmoda.greeter()
end
testmod.ml
let main() =
print_endline "Calling modules now...";
Testmoda.greeter();
Testmodb.dogreet();
print_endline "End."
;;
let _ = main()
现在我产生.mli fil e
ocamlc -c -i testmoda.ml >testmoda.mli
和testmoda.cmi在那里。
接下来,我创建一个没有错误的.cmo文件:
ocamlc -c testmoda.ml
很好,所以做同样的testmodb.ml:
[email protected]:~/Ocaml/ml/testmod> ocamlc -c -i testmodb.ml >testmodb.mli
File "testmodb.ml", line 3, characters 45-61:
Error: Unbound value Testmoda.greeter
闯闯:
[email protected]:~/Ocaml/ml/testmod> ocamlc -c testmoda.cmo testmodb.ml
File "testmodb.ml", line 3, characters 45-61:
Error: Unbound value Testmoda.greeter
其他组合也失败了。
如何编译testmodb.ml和testmod.ml?这应该很容易 - 没有ocamlbuild/omake/ 绿洲,我想。在文件
语法错误被排除在外, 如果我的猫在一起,以一个文件(之间所需的空间)汇编 和完美的执行。
哦奇迹,没有明确的模块定义它按预期工作,'ocamlc -c testmoda.ml'创建.cmi和。cmo,后者可用于编译testmod.ml - 单独编译。 –
(无法编辑评论)所以在这里单独编译:'ocamlc -c testmoda.ml; ocamlc -c testmodb.ml; ocamlc -o testmod testmoda.cmo testmodb.cmo testmod.ml' –
请注意,我给出的单个命令也会分开编译:-)它完全等同于这三个命令。但是,当然有时候你只想编译一个源文件。它也适用于'testmod.ml'。 –