C library bindings: the benefits and shortcomings of `ctypes.foreign`?

Continuing the discussion from Looking for help: Resolve linking issue with ocaml-argon2:

Apologies for vagueness, but I wonder if I should rewrite / avoid usage of ctypes.foreign when dynamic binding is not needed? I used it because of the out-of-the-box initial beginner friendliness under Dune, faced some problems to get it to work but managed without too much hassle once I understood which Dune setting passes arguments where.

Yes, I think you should use ctypes.foreign only in places where you’d use dlopen/dlsym in C (plugins, not libraries). The stubs interface is more appropriate to create a library. I reckon it’s difficult to use though. We have some preliminary support for it in Dune but it’s not ideal at that point (I’d like to improve that this year).

1 Like