t53k
April 3, 2025, 8:24pm
1
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
jmid
April 3, 2025, 9:42pm
2
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)
t53k
April 4, 2025, 5:26am
3
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"
jmid
April 4, 2025, 6:14am
4
Argh 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…
I am thus leaning towards instead suggesting this solution that I just spotted:
opened 12:20PM - 13 May 24 UTC
forwarded-to-js-devs
```
#=== ERROR while compiling base.v0.16.3 ===================================… ====#
# context 2.2.0~beta3~dev | linux/arm64 | ocaml.5.1.1 | https://opam.ocaml.org#2b6e600e
# path ~/.opam/default-clang/.opam-switch/build/base.v0.16.3
# command ~/.opam/opam-init/hooks/sandbox.sh build dune build -p base -j 7
# exit-code 1
# env-file ~/.opam/log/base-12454-0cee78.env
# output-file ~/.opam/log/base-12454-0cee78.out
### output ###
# [...]
# (cd _build/default/src && /usr/bin/clang -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_FILE_OFFSET_BITS=64 -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_LARGEFILE64_SOURCE -mpopcnt -g -I /home/antonin/.opam/default-clang/lib/ocaml -I /home/antonin/.opam/default-clang/lib/sexplib0 -I ../compiler-stdlib/src -I ../hash_types/src -I ../shadow-stdlib/src -o exn_stubs.o -c exn_stubs.c)
# clang: error: unsupported option '-mpopcnt' for target 'aarch64-redhat-linux-gnu'
# File "src/dune", line 14, characters 10-21:
# 14 | (c_names bytes_stubs exn_stubs int_math_stubs hash_stubs am_testing)
# ^^^^^^^^^^^
# (cd _build/default/src && /usr/bin/clang -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_FILE_OFFSET_BITS=64 -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_LARGEFILE64_SOURCE -mpopcnt -g -I /home/antonin/.opam/default-clang/lib/ocaml -I /home/antonin/.opam/default-clang/lib/sexplib0 -I ../compiler-stdlib/src -I ../hash_types/src -I ../shadow-stdlib/src -o bytes_stubs.o -c bytes_stubs.c)
# clang: error: unsupported option '-mpopcnt' for target 'aarch64-redhat-linux-gnu'
# File "src/dune", line 14, characters 47-57:
# 14 | (c_names bytes_stubs exn_stubs int_math_stubs hash_stubs am_testing)
# ^^^^^^^^^^
# (cd _build/default/src && /usr/bin/clang -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_FILE_OFFSET_BITS=64 -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_LARGEFILE64_SOURCE -mpopcnt -g -I /home/antonin/.opam/default-clang/lib/ocaml -I /home/antonin/.opam/default-clang/lib/sexplib0 -I ../compiler-stdlib/src -I ../hash_types/src -I ../shadow-stdlib/src -o hash_stubs.o -c hash_stubs.c)
# clang: error: unsupported option '-mpopcnt' for target 'aarch64-redhat-linux-gnu'
```
It seems that clang doesn't need the flag and that [`__builtin_popcountg`](https://clang.llvm.org/docs/LanguageExtensions.html#builtin-popcountg) should be used.
t53k
April 4, 2025, 6:47am
5
Thank you! I will go with the solution to checkout and remove the -mpopcnt
flags for now.