Fail to compiling ocaml-base-compiler.3.12.0 on macos

Hello all,

  I am trying to install an old ocaml version on my macos.
 `opam switch create compcert-tso ocaml-base-compiler.3.12.0`
 But I got the following errors, could you please give me some suggestions?
#=== ERROR while compiling ocaml-base-compiler.3.12.0 =========================#
# context     2.0.7 | macos/x86_64 |  |
# path        ~/.opam/compcert-tso/.opam-switch/build/ocaml-base-compiler.3.12.0
# command     ~/.opam/opam-init/hooks/ build make world
# exit-code   2
# env-file    ~/.opam/log/ocaml-base-compiler-56675-a00279.env
# output-file ~/.opam/log/ocaml-base-compiler-56675-a00279.out
### output ###
# [...]
# lseek.c:58:3: error: implicit declaration of function 'caml_enter_blocking_section' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
#   caml_enter_blocking_section();
#   ^
# lseek.c:60:3: error: implicit declaration of function 'caml_leave_blocking_section' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
#   caml_leave_blocking_section();
#   ^
# 4 errors generated.
# make[2]: *** [../Makefile.shared:90: lseek.o] Error 1
# make[2]: Leaving directory '/Users/syuan/.opam/compcert-tso/.opam-switch/build/ocaml-base-compiler.3.12.0/otherlibs/unix'
# make[1]: *** [Makefile:656: otherlibraries] Error 2
# make[1]: Leaving directory '/Users/syuan/.opam/compcert-tso/.opam-switch/build/ocaml-base-compiler.3.12.0'
# make: *** [Makefile:138: world] Error 2

I’ve never built software on MacOS, but I’d suggest the following:

  1. try to build this same backlevel ocaml on Linux, with the same version of gcc as you’re using on this mac. Why? b/c that’s the most-used platform, so if the problem still exists there, you can get others to look at it.
  2. if it fails, try with backlevel gcc and with whatever the most-modern GCC is. The latter will allow you to produce a reproducible testcase.
  3. If it works, then get to work on debugging on the Mac: it looks like either a C compiler incompatibility, or include-file weirdness.

I’d put my $$ on include-file weirdness.

Looks like you are using a C compiler which is too recent and that defaults to C99 mode. The source of 3.12 is not C99-compliant.


Also, note that 3.12 won’t work with arm macs.

1 Like

Thx, I will test it this evening, and return the feedback~

ok, thx, I will try an old gcc version :joy: ~

I tested it on ubuntu1~20.04.1, it works very well. I change to Ubuntu now. So Mac needs an older gcc version(maybe 9.3 or …)

Can you share the output of “gcc --version” for your Mac ? I have a Mac, so I could try to build, if I have the same level of GCC (can’t change the level, as it’s a work machine)

FYI, I was able to (partially) build ocaml 3.12.1 using:

gcc --version
Apple clang version 13.1.6 (clang-1316.
Target: x86_64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

It failed while building unix, with a missing inet_addr_of_string – since this is further-along than you got, I figured no point in going further until/unless you got this far also. My suspicion (without digging deeper) is include-file hinkiness.

% gcc --version

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1

Apple clang version 12.0.0 (clang-1200.0.32.28)

Target: x86_64-apple-darwin20.2.0

Thread model: posix

InstalledDir: /Library/Developer/CommandLineTools/usr/bin

thanks for your help~

I could install base-unix, here is the report:

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
+- The following actions failed
| - build ocaml-base-compiler 3.12.0
+- The following changes have been performed (the rest was aborted)
| - install base-bigarray base
| - install base-threads  base
| - install base-unix     base

IIRC, base-unix doesn’t do much. At this point, you should be going beneath opam and running the ./configure and make world commands yourself.