我正在将我的应用程序从OCaml 4.02.3移植到4.03.0。
假设您在lexer.ml中有以下内容
type t = T [@@deriving sexp]
let () =
sexp_of_t |> ignore;
print_endline "hai"我试着运行如下:
ocamlbuild -use-ocamlfind -pkg ppx_sexp_conv -cflags '-w @a-4-31' lexer.byte --但我得到了以下错误:
Warning 31: files lexer.cmo and /Users/vladimir/.opam/4.03.0+flambda/lib/ocaml/compiler-libs/ocamlcommon.cma(Lexer) both define a module named Lexer
File "_none_", line 1:
Error: Some fatal warnings were triggered (1 occurrences)不过,我知道compiler-libs也有一个名为Lexer的模块,它与我的lexer发生了冲突:
ppx_sexp_conv使用它,但它是一个预处理器,它不需要将编译器-libs链接到我的应用程序中。-w @a-4-31)视为一种解决办法,但这是行不通的。它曾在4.02.3中起作用。发布于 2016-05-25 00:40:34
警告31的错误是ocaml 4.03.0编译器的一个新的默认行为。
当您链接两个同名模块时,OCaml会给出警告31。这并不限于4.03.0:
$ touch a.ml
$ ocamlc a.ml a.ml
File "a.cmo", line 1:
Warning 31: files a.cmo and a.cmo both define a module named A
File "a.ml", line 1:
Error: Some fatal warnings were triggered (1 occurrences) <-- This is new in 4.03.0默认情况下,OCaml 4.02.3不将警告31作为错误处理,但OCaml 4.03.0处理:
$ ocamlc -v
The OCaml compiler, version 4.03.0
Standard library directory: /Users/XXX/.opam/4.03.0/lib/ocaml
$ ocamlc -help
...
-warn-error <list> Enable or disable error status for warnings according
to <list>. See option -w for the syntax of <list>.
Default setting is "-a+31"+31发出警告31错误。在OCaml 4.02.3中,默认设置为"-a"。这就是为什么您的代码被拒绝的原因不是4.02.3,而是4.03.0。
解决办法是从+31交换机中删除-warn-error。但总的来说,最好的方法是重命名模块。由于有多个同名的模块,人们有许多链接问题很难找到,这就是为什么31现在默认是一个错误。
附加注意事项
警告31不是编译时警告,而是链接时间警告。因此,如果使用ocamlbuild,就必须用-lflags而不是-cflags来指定-warn-error -a。
https://stackoverflow.com/questions/37415476
复制相似问题