Ocaml base compiler failing to build

I’m following the Real World Ocaml tutorial but when I try to create an env using opam switch create 4.13.1 it says that “the compilation of ocaml-base-compiler.4.13.1 failed”

I searched similar issues but none of them solved my problem, i don’t know what to do now. What am I doing wrong?

That is the output of opam switch create 4.13.1

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

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
∗ installed base-bigarray.base
∗ installed base-threads.base
∗ installed base-unix.base
∗ installed ocaml-options-vanilla.1
⬇ retrieved ocaml-base-compiler.4.13.1  (cached)
[ERROR] The compilation of ocaml-base-compiler.4.13.1 failed at "./configure
        --prefix=/home/felipe/.opam/4.13.1 -C".

#=== ERROR while compiling ocaml-base-compiler.4.13.1 =========================#
# context     2.1.0 | linux/x86_64 |  | https://opam.ocaml.org#45b9c3d5
# path        ~/.opam/4.13.1/.opam-switch/build/ocaml-base-compiler.4.13.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build ./configure --prefix=/home/felipe/.opam/4.13.1 -C
# exit-code   1
# env-file    ~/.opam/log/ocaml-base-compiler-10708-9cdcfe.env
# output-file ~/.opam/log/ocaml-base-compiler-10708-9cdcfe.out
### output ###
# [...]
# configure: Configuring OCaml version 4.13.1
# checking build system type... x86_64-pc-linux-gnu
# checking host system type... x86_64-pc-linux-gnu
# checking target system type... x86_64-pc-linux-gnu
# checking for ld... ld
# checking how to print strings... printf
# checking for gcc... no
# checking for cc... no
# checking for cl.exe... no
# configure: error: in `/home/felipe/.opam/4.13.1/.opam-switch/build/ocaml-base-compiler.4.13.1':
# configure: error: no acceptable C compiler found in $PATH
# See `config.log' for more details



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build ocaml-base-compiler 4.13.1
└─ 
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install base-bigarray         base
│ ∗ install base-threads          base
│ ∗ install base-unix             base
│ ∗ install ocaml-options-vanilla 1
└─ 

<><> ocaml-base-compiler.4.13.1 troubleshooting <><><><><><><><><><><><><><><><>
=> A failure in the middle of the build may be caused by build parallelism
      (enabled by default).
      Please file a bug report at
   https://github.com/ocaml/opam-repository/issues
=> You can try installing again including --jobs=1
      to force a sequential build instead.
# Run eval $(opam env --switch=4.13.1) to update the current shell environment
Switch initialisation failed: clean up? ('n' will leave the switch partially
installed) [Y/n] 

This is the tutorial I’m following: Real World OCaml

You need a C compiler to do any OCaml programming, including compiling the compiler.
If you’re on a Debian derivative, you can likely run apt build-dep ocaml to get everything you need. Other distributions may have similar commands, but if you don’t know them just install either gcc or clang and that should get you at least a little further.

1 Like

Actually I don’t know the commands, i’m a windows user trying to migrate hahaha.
I didn’t have the c compiler, but even after installing it I’m still getting an error.

The output now is

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

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
∗ installed base-bigarray.base
∗ installed base-threads.base
∗ installed base-unix.base
∗ installed ocaml-options-vanilla.1
⬇ retrieved ocaml-base-compiler.4.13.1  (cached)
[ERROR] The compilation of ocaml-base-compiler.4.13.1 failed at "make -j1".

#=== ERROR while compiling ocaml-base-compiler.4.13.1 =========================#
# context     2.1.0 | linux/x86_64 |  | https://opam.ocaml.org#45b9c3d5
# path        ~/.opam/4.13.1/.opam-switch/build/ocaml-base-compiler.4.13.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build make -j1
# exit-code   1
# env-file    ~/.opam/log/ocaml-base-compiler-25227-181a50.env
# output-file ~/.opam/log/ocaml-base-compiler-25227-181a50.out
### output ###
# bwrap: execvp make: No such file or directory



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build ocaml-base-compiler 4.13.1
└─ 
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install base-bigarray         base
│ ∗ install base-threads          base
│ ∗ install base-unix             base
│ ∗ install ocaml-options-vanilla 1
└─ 
# Run eval $(opam env --switch=4.13.1) to update the current shell environment
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [Y/n] 

@edit:
I’m using Ubuntu but I tried to use the sudo apt build-dep ocaml and it didn’t worked as well, it said E: You must put some 'deb-src' URIs in your sources.list

i found out i needed to install make and bubblewrap, but doing it solved this issue and now the opam switch create 4.13.1 worked!!

Thanks a lot @vlaviron

1 Like

You are using Ubuntu on windows WSL2 ? In that case one should first install make and gcc using this script :

sudo apt update        # to update the repo packages
sudo apt install make  # install gnu make
sudo apt install gcc   # install gcc

Only then you can install OCaml from sources or opam switch create.