There are a number of resources out there .
First, you need to mark main.native to create a dependency on c-stubs and links respectively. (By the way, this assumes that the c-library is called cstub , but it could be anything you want).
_tags :
<*.{byte,native}> : use_cstub <**
Then in myocamlbuild.ml create a c library dependency with tagged tags,
dep ["link";"ocaml";"use_cstub"] ["libcstub.a"]
OCamlbuild has rules for creating library files (* .so and * .a), but you will need to add a list of files to be created in the .clib file,
cstub.clib :
cobjfile1.o cobjfile2.o ...
Any header files must also be copied from the main directory to the _build/ directory. This is done by indicating that they depend on compilation in c (in myocamlbuild.ml , where headers is a list of lines that fill the header files in the project.
dep ["c"; "compile"] headers;
and, finally, adding flags when linking the project to the c-stub library (also in myocamlbuild.ml ),
flag ["link";"ocaml";"use_cstub"] (S[A"-dllib";A"-lcstub";A"-cclib";A"-lcstub"]);
source share