Context: I have a stream of file descriptors as text that I want to consume, parse, and do unix-y things like dup2/close/open on in OCaml. The stdlib’s Unix module does not have a way to convert a parsed integer into a file_descr type so I am trying to write my own C bindings. I am using cstubs specifically so I can access C macro constants like open flags, viz. O_RDONLY and O_WRONLY.
So I have this dune stanza to add ctypes to my lib module based on this helpful guide (Binding C libraries in OCaml with the dune ctypes stanza | Michael Bacarella)
(library
(libraries unix)
(name oshell2)
(ctypes
(headers (include “fcntl.h”))
(type_description
(instance Type)
(functor Type_description))
(function_description
(instance Functions)
(functor Function_description))
(generated_types Types_generated)
(generated_entry_point C)))
However this will fail with field external_library_name missing
. I don’t know what to put for the library name when I’m trying to access a posix API. Something like libc won’t work and isn’t appropriate here.
Anyone faced this problem before and have insight into how to link and use OS functionality from OCaml?