There are a number of resources out there.
The first thing is that you need to tag the main.native
as to create a dependency on the c-stubs and link accordingly. (By the way, this assumes the c-library is called cstub
, but it can be anything you'd like).
_tags
:
<*.{byte,native}> : use_cstub
<**/*.cm{x,}a> : use_cstub
Then, in myocamlbuild.ml
create a dependency of a c-library to the things tagged,
dep ["link";"ocaml";"use_cstub"] ["libcstub.a"]
OCamlbuild has rules for creating library files (*.so and *.a), but you would need to add a listing of the files to be built against in a .clib
file,
cstub.clib
:
cobjfile1.o
cobjfile2.o
...
Any header files also need to be copied over from the main directory to the _build/
directory. This is done by specifying they are a dependency on compilation in c (in myocamlbuild.ml
, where headers
is a list of strings naming the header files in the project.
dep ["c"; "compile"] headers;
and finally, adding flags to when we link the project with the c-stub library (also in myocamlbuild.ml
),
flag ["link";"ocaml";"use_cstub"] (S[A"-dllib";A"-lcstub";A"-cclib";A"-lcstub"]);
myocamlbuild.m
and_tags
files. Have you tried it? – Indoxylmyocamlbuild.ml
that adds the required dependency. – Zucchettomyocamlbuild.ml
and other files. The result seems to be compilable without oasis installed . – Indoxyl