Error compiling base

Hello OCaml community,

I try to setup ocaml on my Mac Book air M1 2020 macos Version 15.4

opam init -y
eval $(opam env)
opam install ocaml-lsp-server odoc ocamlformat utop

The installation of the development environment fails because the library base can not be compiled. The problem ist the unsupported cc compiler option ‘-mpopcnt’:

#=== ERROR while compiling base.v0.17.1 =======================================#
# context     2.3.0 | macos/arm64 | ocaml.5.3.0 | https://opam.ocaml.org#1b767795a4e028a4d45f916f1598c24ee7a7b6cb
# path        ~/.opam/default/.opam-switch/build/base.v0.17.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p base -j 7
# exit-code   1
# env-file    ~/.opam/log/base-47427-483383.env
# output-file ~/.opam/log/base-47427-483383.out
### output ###
# [...]
# (cd _build/default/src && /usr/bin/cc -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 -fdiagnostics-color=always -D_LARGEFILE64_SOURCE -mpopcnt -g -I .opam/default/lib/ocaml -I .opam/default/lib/ocaml_intrinsics_kernel -I .opam/default/lib/sexplib0 -I ../hash_types/src -I ../shadow-stdlib/src -o hash_stubs.o -c hash_stubs.c)
# clang: error: unsupported option '-mpopcnt' for target 'arm64-apple-darwin24.4.0'
# File "src/dune", line 19, characters 21-30:
# 19 |   (names bytes_stubs exn_stubs int_math_stubs hash_stubs obj_stubs am_testing)
#                           ^^^^^^^^^
# (cd _build/default/src && /usr/bin/cc -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 -fdiagnostics-color=always -D_LARGEFILE64_SOURCE -mpopcnt -g -I .opam/default/lib/ocaml -I .opam/default/lib/ocaml_intrinsics_kernel -I .opam/default/lib/sexplib0 -I ../hash_types/src -I ../shadow-stdlib/src -o exn_stubs.o -c exn_stubs.c)
# clang: error: unsupported option '-mpopcnt' for target 'arm64-apple-darwin24.4.0'
# (cd _build/default && .opam/default/bin/ocamlopt.opt -w -40 -g -I src/.base.objs/byte -I src/.base.objs/native -I .opam/default/lib/ocaml_intrinsics_kernel -I .opam/default/lib/sexplib0 -I hash_types/src/.base_internalhash_types.objs/byte -I hash_types/src/.base_internalhash_types.objs/native -I shadow-stdlib/src/.shadow_stdlib.objs/byte -I shadow-std[...]
# File "src/array.ml", line 399, characters 28-75:
# 399 |       result := Bool.select ((keep_left_if [@inlined]) (compare x !result)) x !result
#                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Warning 55 [inlining-impossible]: Cannot inline: Unknown function

Can some one help me to fix this?

1 Like

It seems there’s a fix PR for that issue here: Fix popcnt CPU support detection by 0xfedcafe · Pull Request #177 · janestreet/base · GitHub

I would try to pin the branch with the fix

opam pin -y https://github.com/0xfedcafe/base.git

and then retry the opam install ocaml-lsp-server odoc ocamlformat utop above (assuming the pin succeeds) :slightly_smiling_face:

Thank you very much!

Now the cc compilation error is gone, but now some ml code will not compile:

#=== ERROR while compiling base.v0.17.1 =======================================#
# context     2.3.0 | macos/arm64 | ocaml.5.3.0 | pinned(git+https://github.com/0xfedcafe/base.git#69f475d3b9f98beb8b5089d973bc4a5ef8f32d96)
# path        ~/.opam/default/.opam-switch/build/base.v0.17.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p base -j 7
# exit-code   1
# env-file    ~/.opam/log/base-73878-ba32c5.env
# output-file ~/.opam/log/base-73878-ba32c5.out
### output ###
# Error: This variant expression is expected to have type "Sexplib0__.Sexp.t"
# [...]
# (cd _build/default && /.opam/default/bin/ocamlopt.opt -w -40 -g -I src/.base.objs/byte -I src/.base.objs/native -I /.opam/default/lib/ocaml_intrinsics_kernel -I /.opam/default/lib/sexplib0 -I hash_types/src/.base_internalhash_types.objs/byte -I hash_types/src/.base_internalhash_types.objs/native -I shadow-stdlib/src/.shadow_stdlib.objs/byte -I shadow-std[...]
# File "src/obj_local.ml", line 57, characters 7-17:
# 57 |        sexp__002_
#             ^^^^^^^^^^
# Warning 20 [ignored-extra-argument]: this argument will not be used by the function.
#
# File "src/obj_local.ml", line 56, characters 9-39:
# 56 |        [ "Immediate"; "Stack"; "Heap" ]
#               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Error: This variant expression is expected to have type "Sexplib0__.Sexp.t"
#        There is no constructor "::" within type "Sexplib0__.Sexp.t"


Argh :grimacing: I can see the interface of that function changed in the latest
v0.17~preview.129.36+325 to now take a list History for src/sexp_conv_error.ml - janestreet/sexplib0 · GitHub
The latest sexplib0 on the opam-repo uses the v0.17.0 tagged release however…

One option is to similarly pin the sexplib0 library as above, then pin base, and then opam install the rest. I can’t guarantee that you won’t hit some other cross-package incompatibility unfortunately… :person_shrugging:

I am thus leaning towards instead suggesting this solution that I just spotted:

Thank you! I will go with the solution to checkout and remove the -mpopcnt flags for now.