Dune fails to compile my library with pyml

So I was trying to use pyml in my project GitHub - thierry-martinez/pyml: OCaml bindings for Python

and it turns out that just adding pyml to dune libraries makes my project crash on linking with :

/usr/bin/ld: cannot find -lposixat_stubs
/usr/bin/ld: cannot find -lshexp_bigstring_io_stubs
/usr/bin/ld: cannot find -lshexp_bigstring_stubs
/usr/bin/ld: cannot find -lbase_stubs
/usr/bin/ld: cannot find -lbase_internalhash_types_stubs
/usr/bin/ld: cannot find -lspawn_stubs
/usr/bin/ld: cannot find -lnumpy_stubs
/usr/bin/ld: cannot find -lpyml_stubs
/usr/bin/ld: cannot find -lstdcompat__stubs

Curiously, it only happens on my real life project - here is the dune file

 (name main)    
 (public_name mm_bench)    
 (modes byte native)    
 (libraries batteries  pyml streaming shexp.process tensor_loops re ppx_deriving)    
 (preprocess (pps ppx_deriving.show ppx_deriving.ord ppx_deriving.eq    
 ppx_deriving.ord ))    
 (package mm_bench)    

Because when I try to use pyml in a toy project it runs perfectly (the toy project being the one described in pyml README). So I am not sure it is even a bug specific to pyml.

I may fill an issue on pyml github but I first wanted to know if anyone has ever encountered a linking bug in dune and what are the probable causes. There is a chance that the issue arises from trying to link with C stubs. I’m trying to reproduce a minimal error configuration but it’s difficult. The problem arises with both ocaml 4.12 and ocaml 4.10. Any help would be appreciated.

Thanks !

EDIT : Ok, found it, pyml fails to compile in byte mode. I will fill an issue on github.

1 Like

I had a similar issue when using pythonlib and a workaround consisted in adding some folders to $LIBRARY_PATH. See here for details.

Also, in case this is relevant to you, I uploaded an example of how to use pyml and pythonlib to expose OCaml libraries to Python. You can look at it here.


This was not what I was looking for but this is actually extremely relevant :slight_smile: Thanks !

Sorry for not having answered earlier and thank you very much for reporting! The problem appears to be that, when building your executable, ocamlc calls ld with the options -L. -lpyml_stubs (and the same pattern for the other libraries): these are the options passed to ocamlc for building pyml.cma (pyml's Makefile line 116: -cclib "-L. -lpyml_stubs"). Obviously, the -L. is wrong and should be something like -L~/.opam/4.12/lib/pyml, but I don’t know how to fix that properly: when building pyml.cma, pyml's Makefile doesn’t know where ocamlfind will install it (and doesn’t even know if it will be installed or used in place, for example to run test files, for which -L. is the correct option to pass). Any ideas? I will continue to look for a solution…