【问题标题】:OCaml compile error with ocamlfind使用 ocamlfind 的 OCaml 编译错误
【发布时间】:2014-04-24 03:33:51
【问题描述】:

代码如下:

class parser =

let test1 = function
| 1 -> print_int 1
| 2 -> print_int 2
| _ -> print_int 3 in

let test = function
| 1 -> print_int 1
| 2 -> print_int 2
| _ -> print_int 3 in

object(self)

end

这里是_tags

true: syntax(camlp4o)
true: package(deriving,deriving.syntax)
true: thread,debug,annot
true: bin_annot

这里是编译命令:

ocamlbuild -use-ocamlfind test.native

这里是编译错误:

Warning: tag "package" does not expect a parameter, but is used with parameter   "deriving,deriving.syntax"
Warning: tag "syntax" does not expect a parameter, but is used with parameter "camlp4o"
+ /usr/local/bin/ocamldep.opt -modules test.ml > test.ml.depends
File "test.ml", line 8, characters 0-3:
Error: Syntax error
Command exited with code 2.
Compilation unsuccessful after building 1 target (0 cached) in 00:00:00.

但是,当我使用这个时:

ocamlbuild test.native

那么代码就可以编译成功了……

【问题讨论】:

    标签: ocaml ocamlfind


    【解决方案1】:

    这是因为ocamlbuild -use-ocamlfind test.native 指示编译器使用camlp4 解析器。它与标准的 OCaml 解析器有点不同。其实parser是camlp4中的关键字,所以不能作为类名使用。重命名就好了。

    【讨论】:

    • 是的,我没想到会出现这种错误,谢谢!