ocamlopamutop

Trying to install utop for OCaml in Fedora 26; got an error about installing LWT


I currently have Fedora 26 installed, and I have installed the following packages:

sudo dnf install opam ocaml gcc gcc-c++ m4 make ocamldoc sqlite-devel libcurl-devel fuse-devel zlib-devel ocaml-camlp4-devel redhat-rpm-config

This is the error I currently get trying to install utop:

#=== ERROR while installing lwt.2.7.1 =========================================#
# opam-version 1.2.2
# os           linux
# command      make build
# path         /home/z/.opam/system/build/lwt.2.7.1
# compiler     system (4.02.3)
# exit-code    2
# env-file     /home/z/.opam/system/build/lwt.2.7.1/lwt-21869-a00279.env
# stdout-file  /home/z/.opam/system/build/lwt.2.7.1/lwt-21869-a00279.out
# stderr-file  /home/z/.opam/system/build/lwt.2.7.1/lwt-21869-a00279.err
### stdout ###
# ./setup.exe -build 
# ocamlfind ocamlopt -package unix -package ocamlbuild -linkpkg -package cppo_ocamlbuild myocamlbuild.ml /usr/lib64/ocaml/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
# + ocamlfind ocamlopt -package unix -package ocamlbuild -linkpkg -package cppo_ocamlbuild myocamlbuild.ml /usr/lib64/ocaml/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
# File "myocamlbuild.ml", line 1:
# Error: Files /home/z/.opam/system/lib/cppo_ocamlbuild/ocamlbuild_cppo.cmxa
#        and /usr/lib64/ocaml/ocamlbuild/ocamlbuildlib.cmxa
#        make inconsistent assumptions over implementation Ocamlbuild_plugin
# Command exited with code 2.
# Makefile:33: recipe for target 'build' failed
### stderr ###
# W: Cannot find source file matching module 'Lwt_unix' in library lwt-unix.
# W: Use InterfacePatterns or ImplementationPatterns to define this file with feature "source_patterns".
# W: Cannot find source file matching module 'Lwt_unix' in library lwt-unix.
# W: Use InterfacePatterns or ImplementationPatterns to define this file with feature "source_patterns".
# E: Failure("Command ''/usr/bin/ocamlbuild' src/core/lwt.cma src/core/lwt.cmxa src/core/lwt.a src/core/lwt.cmxs src/logger/lwt-log.cma src/logger/lwt-log.cmxa src/logg$r/lwt-log.a src/logger/lwt-log.cmxs src/unix/liblwt-unix_stubs.a src/unix/dlllwt-unix_stubs.so src/unix/lwt-unix.cma src/unix/lwt-unix.cmxa src/unix/lwt-unix.a src/unix$lwt-unix.cmxs src/simple_top/lwt-simple-top.cma src/simple_top/lwt-simple-top.cmxa src/simple_top/lwt-simple-top.a src/simple_top/lwt-simple-top.cmxs src/react/lwt-reac$.cma src/react/lwt-react.cmxa src/react/lwt-react.a src/react/lwt-react.cmxs src/preemptive/lwt-preemptive.cma src/preemptive/lwt-preemptive.cmxa src/preemptive/lwt-pre$mptive.a src/preemptive/lwt-preemptive.cmxs src/ppx/ppx.cma src/ppx/ppx.cmxa src/ppx/ppx.a src/ppx/ppx.cmxs src/ppx/ppx_lwt_ex.native doc/examples/unix/logging.native d$c/examples/unix/relay.native doc/examples/unix/parallelize.native -use-ocamlfind -plugin-tags 'package(cppo_ocamlbuild)' -tag debug' terminated with error code 10")
# make: *** [build] Error 1

What should I do?

Thank you!


Solution

  • Opam's "system compiler", that is used by default on opam init, is an hybrid setting in which the packages are installed in the local opam sandbox, but the compiler from the system (/usr) is used. See the opam switch command to use a sandbox with a compiler compiled by opam instead, or to switch back.

    Your example shows that you are using a system compiler, as provided by dnf install ocaml ; opam is consequently supposed to use e.g. /usr/bin/ocamlopt, but installed software and libs from ~/.opam/system/{bin,lib}.

    What is supposed to happen is that lwt depends on ocamlbuild and ocamlfind, which opam installs first; then PATH is set so that ~/.opam/system/bin/ is first and these installed binaries are always chosen. It's where something must be going wrong, because the end of the log shows that /usr/bin/ocamlbuild was called.

    It's difficult to know what without more details, and I failed to reproduce on a Fedora 25 container. But you could:

    Of course, as mentionned in the comments above, using a standard (i.e. non-system) switch, which includes its own OCaml compiler, would work around the issue. It takes a tad longer to compile though.