OCaml警告31,编译器库和ppx [英] OCaml warning 31, compiler-libs, and ppx
问题描述
我正在将应用程序从OCaml 4.02.3移植到4.03.0.
I'm porting my application from OCaml 4.02.3 to 4.03.0.
假设您在lexer.ml
中具有以下内容:
Say you have the following in lexer.ml
:
type t = T [@@deriving sexp]
let () =
sexp_of_t |> ignore;
print_endline "hai"
我正在尝试按以下方式运行它:
I'm trying to run it as following:
ocamlbuild -use-ocamlfind -pkg ppx_sexp_conv -cflags '-w @a-4-31' lexer.byte --
但是我遇到了以下错误:
But I'm getting the following error:
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
的模块,但是它与我的词法分析器冲突,但是:
I understand that compiler-libs
has a module called Lexer
as well and it clashes with my lexer, however:
-
我不是要链接编译器库.我知道
ppx_sexp_conv
使用了它,但是它是一个预处理程序,不需要将编译器库链接到我的应用程序中.
I'm not trying to link compiler-libs. I understand that it is used by
ppx_sexp_conv
, but it's a preprocessor, it should not need to link compiler-libs into my app.
警告31只是警告,我明确尝试将其取消(-w @a-4-31
)作为解决方法,但这不起作用.它曾经在4.02.3中工作.
Warning 31 is just a warning, and I'm explicitly trying to dismiss it (-w @a-4-31
) as a workaround, but that does not work. It used to work in 4.02.3.
推荐答案
警告31的错误是ocaml 4.03.0编译器的新默认行为.
This error of Warning 31 is a new default behaviour of ocaml 4.03.0 compiler.
OCaml会给您发出警告31.这不是特定于4.03.0的:
OCaml gives you Warning 31 when you link two modules of the same name. This is not specific to 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可以:
OCaml 4.02.3 does not handle Warning 31 as an error by default, but OCaml 4.03.0 does:
$ 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
makes Warning 31 error. In OCaml 4.02.3, the default setting is "-a"
. That's why your code is rejected not by 4.02.3 but by 4.03.0.
一种解决方法是从-warn-error
开关中删除+31
.但是最好的办法通常是重命名您的模块.人们通过拥有多个同名模块而很难找到许多链接问题,这就是为什么默认情况下31现在是错误的原因.
A workaround is to remove +31
from -warn-error
switch. But the best in general is to rename your module. People have had many linking troubles hard to track down by having more than one module with the same name, and this is why 31 is now an error by default.
警告31不是编译时警告,而是链接时间警告.因此,如果使用ocamlbuild
,则必须用-lflags
而不是-cflags
指定-warn-error -a
.
Warning 31 is not a compile time warning but a link time one. Therefore if you use ocamlbuild
, you have to specify -warn-error -a
with -lflags
instead of -cflags
.
这篇关于OCaml警告31,编译器库和ppx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!