2

I'm porting my application from OCaml 4.02.3 to 4.03.0.

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)

I understand that compiler-libs has a module called Lexer as well and it clashes with my lexer, however:

  • 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.

  • 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.

Vladimir Keleshev
  • 13,753
  • 17
  • 64
  • 93
  • 1
    This seems to be a ocamlbuild bug. Have you tried reporting it to them? – PatJ May 24 '16 at 13:50
  • Regarding linking problem: I've also found that using ppx rewriters lead to linking against ton of stuff. To overcome this, I use separate compilation and linking phases via `_tags` file: `: package(ppx_jsobject_conv)` & `"src/core.byte": package(ppx_jsobject_conv.runtime)`. – larhat May 24 '16 at 15:06
  • @PatJ, no this is not an ocamlbuild bug. – camlspotter May 25 '16 at 00:10

1 Answers1

4

This error of Warning 31 is a new default behaviour of ocaml 4.03.0 compiler.

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 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 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.

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.

Additional note

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.

camlspotter
  • 8,990
  • 23
  • 27
  • Thanks a lot. That answers why `-w @a-4-31` does not help, although I would say it is bad usability that 31 is a special warning that cannot be disable normally. However, I'm still trying to avoid linking to compiler-libs in the first place. – Vladimir Keleshev May 26 '16 at 08:54
  • 1
    Actually the `-warn-error -a` workaround doesn't seem to work. I get the same error with the following command: `ocamlbuild -use-ocamlfind -pkg ppx_sexp_conv -cflags '-w @a-4-31 -warn-error -a' lexer.byte --` for the `lexer.ml` above. – Vladimir Keleshev May 26 '16 at 09:02
  • 2
    Warning 31 is for linking. Use `-lflags '-warn-error -a'` instead of `-cflags`. (That's why I do not use ocamlbuild. Too many things are hidden under its hood. Normally it is ok, but once troubled, you get really screwed.) – camlspotter May 26 '16 at 09:19