Ocaml no longer produces .a files

Hi !
We are currently create .a static libraries that only have C stubs using ocamlopt -a -o foo.cmxa foo.c. We are using ocaml 4.10.2 and this command produces a foo.a file.

I’m trying to upgrade to 4.12.1, and the same command no longer produces a .a file, only a .o.
It looks like it only happens for pure C library. If there’s a .ml file into the mix, the .a is generated.

Is it expected ? If so, what motivated this change and what would be the right way to recover my .a file ?


Your .a files were likely empty anyway (foo.a will only contain the code for the OCaml objects).
Keep in mind that ocamlopt isn’t a C compiler; if you want to produce a C library, it’s better to use the right tools for that.

That said, what you’re looking for is probably ocamlmklib. Here is one possible usage:

# Compile foo.c, with the relevant include paths for OCaml stubs
ocamlopt -c -o foo.o foo.c
# Create a library
ocamlmklib -o foo foo.o
# You should have a library libfoo.a with your stubs. If you had ml modules foo.a would contain the object code for them.

I see, thanks for the explanation

Yes this is expected since OCaml 4.12 when the archive produced would have been empty.

See Allow linking empty .cmxa files on MSVC by dra27 · Pull Request #9011 · ocaml/ocaml · GitHub for more information