-for-pack link failure

Hello,

I am trying to dynamically load ocaml code. Everything is fine in 4.14. And everything is fine in 5.1.1 with the bytecode compiler. But with the native compiler, I get:

ocamlopt.opt -shared -o /tmp/ocaml_cocci_a8516d.cmxs -g -I /home/julia/main_cocci/ocaml -I /home/julia/.opam/5.1.1/lib/ocaml /tmp/ocaml_cocci_a8516d.ml
File “/tmp/ocaml_cocci_a8516d.ml”, line 1:
Error: /home/julia/main_cocci/ocaml/coccilib.cmx
was built with -for-pack Coccinelle_modules, but the
current unit Ocaml_cocci_a8516d is not

Is there something that changed between 4.14 and 5.1.1 with respect to this issue?

thanks,
julia

Yes: https://github.com/ocaml/ocaml/pull/1391

This PR makes it an error to link directly to an unit that has been packed from outside the pack. In your case, I expect that the (generated?) file ocaml_cocci_a8516d.ml refers directly to Coccilib instead of Coccinelle_modules.Coccilib. This can probably be fixed by adding open Coccinelle_modules at the start of the file, or adding -open Coccinelle_modules to the command-line flags.

Thanks for the suggestion!

Actually, it was necessary to add -for-pack Coccinelle_modules to the compilation of the generated code. That seems to both compile and run in 5.1.1. Thanks.