我有一个结构如下的项目:
Makefile
src/
main.ml
tests/
tests.mlMakefile是这样的:
tests:
ocamlbuild -Is src,tests tests.byte -build-dir $(BUILDDIR) $(TESTFLAGS) -lflags -I,/usr/lib/ocaml/oUnit -cflags -I,/usr/lib/ocaml/oUnit -libs oUnit运行make tests (在构建main.byte之后)返回以下错误:
ocamlbuild -Is src,tests tests.byte -build-dir build -lflags -I,/usr/lib/ocaml/oUnit -cflags -I,/usr/lib/ocaml/oUnit -libs oUnit
+ /usr/bin/ocamlc -c -I /usr/lib/ocaml/oUnit -I tests -I src -o tests/tests.cmo tests/tests.ml
File "tests/tests.ml", line 3, characters 46-50:
Error: Unbound value main
Command exited with code 2.
Compilation unsuccessful after building 2 targets (0 cached) in 00:00:00.
make: *** [tests] Error 10显示ocamlbuild不能链接到main.byte。Makefile的tests规则应该是什么样子的?
发布于 2014-02-24 02:57:39
由于OCaml程序没有默认的主函数(OCaml只在启动时运行每个模块中的顶级代码),因此您可能希望有一个单独的文件来启动代码。例如:
main.ml
myprog.ml
tests.ml其中:
main.ml定义了一个let main args = ...myprog.ml直接调用它的主函数:let () = Main.main Sys.argvtests.ml以相同的方式从每个测试用例中调用它
然后构建myprog.byte和tests.byte作为要构建的两个目标。运行myprog.byte来运行程序,运行tests.byte来运行测试。
发布于 2014-03-01 18:43:38
unbound value main听起来不像是与main.byte相关的错误,而是tests.ml的OCaml代码中的真正错误。你能提供(可能简化的)资源来做实验吗?
(托马斯关于程序结构的建议当然仍然是独立的。)
https://stackoverflow.com/questions/21962501
复制相似问题