Anybody seeing problems building OCaml versions on Ubuntu 26.04.1 LTS?

Recently I upgraded my home server from Ubuntu LTS 24 to LTS 26.
I had an opam (2.5.2) installation [ETA though, I upgraded that to opam 2.6.1; I doubt that that’s the problem, since the failure is in the C compilation stage of the OCaml compiler build – though I could be wrong] in which I’d installed every major
OCaml versions from 4.11.2->5.5.1; I use this to test my packages
against a range of OCaml versions.

I periodically wipe and recreate these switches using a mechanical process,
and I did this today. Oddly, everything except

  • 5.0.0
  • 4.13.1
  • 4.12.1
  • 4.11.2

built just fine. These all got a similar error, and I paste the message below.
Has anybody else encountered this? I can’t back up to the previous install
of Ubuntu (this is a bare-metal install, not a docker image) so I can’t find out
what’s busted, but it’s odd that 4.14.2 worked fine when the versions
before-and-after did not.

Anyway, just figured I’d ask to see if anybody had seen this. I’ve been using this server
for hacking OCaml for … years and years, so this is a little surprising. I can go debug
further (it’s not a problem for me to dive into the C code, run the build manually, etc)
but before I do that, I figured I should ask if anybody else had encountered this. No point
in wasted labor.

    4.13.1: #=== ERROR while compiling ocaml-base-compiler.4.13.1 =========================#
    4.13.1: # context              2.6.1 | linux/x86_64 |  | https://opam.ocaml.org#e4cd7ede2d55a46570977c0ffaa7e96845190817
    4.13.1: # path                 ~/Hack/Opam/GENERIC/4.13.1/.opam-switch/build/ocaml-base-compiler.4.13.1
    4.13.1: # command              ~/Hack/Opam/GENERIC/opam-init/hooks/sandbox.sh build make -j15
    4.13.1: # exit-code            2
    4.13.1: # env-file             ~/Hack/Opam/GENERIC/log/ocaml-base-compiler-182838-27c646.env
    4.13.1: # output-file          ~/Hack/Opam/GENERIC/log/ocaml-base-compiler-182838-27c646.out
    4.13.1: ### output ###
    4.13.1: # [...]
    4.13.1: # caml/prims.h:33:23: error: too many arguments to function ‘(value (*)(void))*(caml_prim_table.contents + (sizetype)((long unsigned int)*pc * 8))’; expected 0, have 2
    4.13.1: #    33 | #define Primitive(n) ((c_primitive)(caml_prim_table.contents[n]))
    4.13.1: #       |                      ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4.13.1: # interp.c:967:14: note: in expansion of macro ‘Primitive’
    4.13.1: #   967 |       accu = Primitive(*pc)(sp + 2, nargs);
    4.13.1: #       |              ^~~~~~~~~
    4.13.1: # make[2]: *** [Makefile:366: interp.b.o] Error 1
    4.13.1: # make[2]: *** Waiting for unfinished jobs....
    4.13.1: # make[2]: Leaving directory '/home/chet/Hack/Opam/GENERIC/4.13.1/.opam-switch/build/ocaml-base-compiler.4.13.1/runtime'
    4.13.1: # make[1]: *** [Makefile:163: coldstart] Error 2
    4.13.1: # make[1]: Leaving directory '/home/chet/Hack/Opam/GENERIC/4.13.1/.opam-switch/build/ocaml-base-compiler.4.13.1'
    4.13.1: # make: *** [Makefile:311: world.opt] Error 2

Ubuntu 26 ships GCC 15 now which defaults to c23 which breaks backward compatibility (Arch btw)

I’m guessing that at some point that PR will be ported across to other supported OCaml releases ?
Would it make sense for people like me to revert to GCC 14 for the interim ?
ETA: And THANK YOU for your answer!
ETA2: I found a forum post explaining how to easily use a different GCC. Just prepend “env GCC=gcc-13” (or whatever) to the “opam switch create” line.

Though, I was creating the switch “empty”, and then installing the ocaml-base-compiler package in it, so I had to prepend the above to the package-install command. I’ll see later if this is something I need to prepend to all package-install commands.

I’m also annoyed by this bug as i have one opam switch for each version of the compiler since 4.02 on my work machine. The issue is currently tracked in ocaml/opam-repository#28250 (which also includes a workaround)

You should set CFLAGS=-std=gnu17 in the environment.

It’s a better workaround than setting the compiler variable (GCC or CC, who knows?) and possibly having to install multiple versions of the C compiler. You’ll also benefit from the latest features and bugfixes of the compiler, while keeping the setting of the C standard.

There are possibly other opam packages using C that are not entirely compatible with C23.

grin The Ubuntu upgrade process installed the new compiler alongside the old one. And haha, alongside the even-older one. I guess I could try to figure out how to uninstall these older versions, but … naaaah, too lazy. Your point is a good one: I feel a little uncomfortable with this “specify older compiler” hack, wondering if some package I install will ignore the indication. specifying a syntax would be much better.

Thank you! I’ll do this the next time I re-create all my switches (which don’t be too long, since I do I periodically).

If you’re using Ubuntu or Debian derivatives you can also use the update-alternatives script to set the default gcc / cc link, and have multiple versions of GCC / Clang installed. It works well.

grin You’re right about this, and Google offered up this choice. But

  • I was already a little reluctant to do it, b/c then I’d have to remember to undo it later
  • notwithstanding, I proceeded to try the suggestions, and they failed. Don’t know why.

So then I learned that opam respected environment variables for CC, etc.

P.S. I don’t know why it failed. 15yr ago, I used to install my machines with
Knoppix, hand-partitioning, hand-install grub, hand-invoke debootstrap. The
whole nine yards. Back then I used to build my own custom kernels for new
Stinkpad hardware (e.g. graphics but not only). But since then I just use the
Ubuntu installer. It’s lazy, I know. And bit-by-bit, I start to no longer -actually-
understand how my systems are constructed.

Ah well. The way of all flesh, I guess.

Happen to me on every new Ubuntu version.

So I moved to Nobara & Omarchy now.