Can't build base compiler (and some other things) with OPAM

I haven’t used OCaml or OPAM in a couple months, and in the intervening time, I upgraded Ubuntu 22.04 to 24.04. Not sure if that matters, but thought you should know.

Anyway I tried to install the server for VSCoq today and got lots of errors.

An example:

$ opam pin add coq 8.18.0                                     
[misc messages]
[ERROR] The compilation of ocaml.4.11.2 failed at "ocaml /home/ninjaaron/.opam/4.11.2+flambda/share/ocaml-config/gen_ocaml_config.ml 4.11.2 ocaml".

#=== ERROR while compiling ocaml.4.11.2 =======================================#
# context     2.2.1 | linux/x86_64 | ocaml-variants.4.11.2+flambda | https://opam.ocaml.org#08323f3c377fcf2b812d13ae4c3581a6f29f3e59
# path        ~/.opam/4.11.2+flambda/.opam-switch/build/ocaml.4.11.2
# command     ~/.opam/opam-init/hooks/sandbox.sh build ocaml /home/ninjaaron/.opam/4.11.2+flambda/share/ocaml-config/gen_ocaml_config.ml 4.11.2 ocaml
# exit-code   1
# env-file    ~/.opam/log/ocaml-38724-f8e142.env
# output-file ~/.opam/log/ocaml-38724-f8e142.out
### output ###
# bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted


#=== ERROR while compiling conf-pkg-config.3 ==================================#
# context     2.2.1 | linux/x86_64 | ocaml-variants.4.11.2+flambda | https://opam.ocaml.org#08323f3c377fcf2b812d13ae4c3581a6f29f3e59
# path        ~/.opam/4.11.2+flambda/.opam-switch/build/conf-pkg-config.3
# command     ~/.opam/opam-init/hooks/sandbox.sh build pkg-config --help
# exit-code   1
# env-file    ~/.opam/log/conf-pkg-config-38724-e254a6.env
# output-file ~/.opam/log/conf-pkg-config-38724-e254a6.out
### output ###
# bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted


#=== ERROR while compiling conf-gmp.4 =========================================#
# context     2.2.1 | linux/x86_64 | ocaml-variants.4.11.2+flambda | https://opam.ocaml.org#08323f3c377fcf2b812d13ae4c3581a6f29f3e59
# path        ~/.opam/4.11.2+flambda/.opam-switch/build/conf-gmp.4
# command     ~/.opam/opam-init/hooks/sandbox.sh build sh -exc cc -c $CFLAGS -I/usr/local/include test.c
# exit-code   1
# env-file    ~/.opam/log/conf-gmp-38724-da4620.env
# output-file ~/.opam/log/conf-gmp-38724-da4620.out
### output ###
# bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
β”Œβ”€ The following actions failed
β”‚ Ξ» build conf-gmp        4
β”‚ Ξ» build conf-pkg-config 3
β”‚ Ξ» build ocaml           4.11.2
└─ 
β”Œβ”€ The following changes have been performed (the rest was aborted)
β”‚ ⊘ remove    ocaml        4.11.2
β”‚ ↻ recompile ocaml-config 1
└─ 
# Run eval $(opam env) to update the current shell environment
[NOTE] Pinning command successful, but your installed packages may be out of sync.

The former state can be restored with:
    /usr/local/bin/opam switch import "/home/ninjaaron/.opam/4.11.2+flambda/.opam-switch/backup/state-20241105083416.export"

Didn’t feel great about that. Tried upgrading all my packages.

$ opam update
[exits without error]
$ opam upgrade
[truncated]
#=== ERROR while compiling ocaml-base-compiler.5.1.0 ==========================#
# context     2.2.1 | linux/x86_64 |  | https://opam.ocaml.org#08323f3c377fcf2b812d13ae4c3581a6f29f3e59
# path        ~/.opam/5.1.0/.opam-switch/build/ocaml-base-compiler.5.1.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build ./configure --prefix=/home/ninjaaron/.opam/5.1.0 --docdir=/home/ninjaaron/.opam/5.1.0/doc/ocaml -C
# exit-code   1
# env-file    ~/.opam/log/ocaml-base-compiler-41587-95f2fc.env
# output-file ~/.opam/log/ocaml-base-compiler-41587-95f2fc.out
### output ###
# bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
β”Œβ”€ The following actions failed
β”‚ Ξ» build ocaml-base-compiler 5.1.0
└─ 
╢─ No changes have been performed

Don’t like that much either. Tried building the latest switch, since rebuilding my current compiler seems to be a no-go.

$ opam switch create 5.2.0 

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Switch invariant: ["ocaml-base-compiler" {= "5.2.0"} | "ocaml-system" {= "5.2.0"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved ocaml-config.3  (cached)
βˆ— installed base-bigarray.base
βˆ— installed base-threads.base
βˆ— installed base-unix.base
βˆ— installed host-arch-x86_64.1
βˆ— installed host-system-other.1
βˆ— installed ocaml-options-vanilla.1
⬇ retrieved ocaml-base-compiler.5.2.0  (cached)
[ERROR] The compilation of ocaml-base-compiler.5.2.0 failed at "./configure --prefix=/home/ninjaaron/.opam/5.2.0 --docdir=/home/ninjaaron/.opam/5.2.0/doc/ocaml -C".

#=== ERROR while compiling ocaml-base-compiler.5.2.0 ==========================#
# context     2.2.1 | linux/x86_64 |  | https://opam.ocaml.org#08323f3c377fcf2b812d13ae4c3581a6f29f3e59
# path        ~/.opam/5.2.0/.opam-switch/build/ocaml-base-compiler.5.2.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build ./configure --prefix=/home/ninjaaron/.opam/5.2.0 --docdir=/home/ninjaaron/.opam/5.2.0/doc/ocaml -C
# exit-code   1
# env-file    ~/.opam/log/ocaml-base-compiler-43790-7416e1.env
# output-file ~/.opam/log/ocaml-base-compiler-43790-7416e1.out
### output ###
# bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
β”Œβ”€ The following actions failed
β”‚ Ξ» build ocaml-base-compiler 5.2.0
└─ 
β”Œβ”€ The following changes have been performed (the rest was aborted)
β”‚ βˆ— install base-bigarray         base
β”‚ βˆ— install base-threads          base
β”‚ βˆ— install base-unix             base
β”‚ βˆ— install host-arch-x86_64      1
β”‚ βˆ— install host-system-other     1
β”‚ βˆ— install ocaml-options-vanilla 1
└─ 
# Run eval $(opam env --switch=5.2.0) to update the current shell environment
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [y/n] y

So, I apparently can’t compile compilers. What should I do?

1 Like

Found more information about this problem:

1 Like