【问题标题】:ocamlbuild and OUnitocamlbuild 和 OUnit
【发布时间】:2014-02-23 00:19:19
【问题描述】:

我的项目结构如下:

Makefile
src/
  main.ml
tests/
  tests.ml

Makefile 是这样的:

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.byteMakefiletests 规则应该是什么样的?

【问题讨论】:

    标签: makefile ocaml ocamlbuild ounit


    【解决方案1】:

    由于 OCaml 程序没有默认的 main 函数(OCaml 只是在启动时运行每个模块中的顶级代码),您可能需要一个单独的文件来启动代码。例如

    main.ml
    myprog.ml
    tests.ml
    

    地点:

    • main.ml 定义了一个主函数 let main args = ...
    • myprog.ml 就这么称呼它:let () = Main.main Sys.argv
    • tests.ml 在每个测试用例中以相同的方式调用它

    然后构建 myprog.bytetests.byte 作为 ocamlbuild 的两个目标。运行myprog.byte 运行程序,运行tests.byte 运行测试。

    【讨论】:

      【解决方案2】:

      unbound value main 听起来不像是与main.byte 相关的错误,而是tests.ml 的OCaml 代码中的真正错误。您能否提供(可能是简化的)实验来源?

      (当然,Thomas 关于程序结构的建议仍然独立。)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-05
        • 1970-01-01
        相关资源
        最近更新 更多