[Omake] OCAML_LIBS and OCAMLFINDFLAGS

Michael Ekstrand michael at elehack.net
Sun Jun 20 05:26:42 PDT 2010


On 06/19/2010 11:31 PM, Sashan Govender wrote:
> Hi
> 
> I have a set of libraries in my project. One of them (libtracer) is
> plain OCaml code, libtracerp4 is a campl4 library over libtracer and
> the other library (libzygote) depends on it. So the dependency chain
> looks like this:
> 
> libtracer->libtracerp4->libzygote
> 
> However if I cd into the libzygote build directory and try to build
> things this is what I get:
> 
> - scan build/libzygote scan-ocaml-IPv4Header.ml
> + ocamlfind ocamldep -verbose -pp 'camlp4orf -I
> /usr/lib64/ocaml/bitstring bitstring.cma bitstring_persistent.cma
> pa_bitstring.cmo -I ../libtracer libtracer.cma -I ../libtracerp4
> libtracerp4.cma' -package bitstring,unix -modules IPv4Header.ml
>      | Shell.ocamldep-postproc()
> Camlp4: Uncaught exception: DynLoader.Error ("libtracer.cma", "file
> not found in path")
> 
> 
> This is what my OCAMLFINDFLAGS looks like:
> 
> OCAMLFINDFLAGS = -verbose -pp 'camlp4orf -I /usr/lib64/ocaml/bitstring
> bitstring.cma bitstring_persistent.cma \
>   pa_bitstring.cmo -I ../libtracer libtracer.cma -I ../libtracerp4 \
>   libtracerp4.cma'
> 
> I also specify that an OCAML_LIBS variable because I thought that this
> is what's used to specify libraries that this library depends on.
> 
> OCAML_LIBS += ../libtracer ../libtracerp4
> 
> It fails because a dependent library, libtracer, isn't built. So how
> do I specify this correctly? Is OCAML_LIBS the right variable to use
> to specify a dependent library.

Yes, but...

I think the issue is in the dependency scanner.  Specifically, while
OMake knows that libtracer and libtracerp4 are needed to link the final
program, it does not know that their cma files are needed to parse
libzygote's source to compile and generate dependencies.  I dealt with
this same problem myself, and finally solved it by adding rules of the
following form to teach it about the dependency (warning, this
particular code is untested, it is a distillation of the relevant parts
of my OMakefile):

PP_DEPS = ../libtracer.cma ../libtracerp4.cma
foreach(mod, $(MODS_IN_LIBZYGOTE))
    .SCANNER: scan-ocaml-$(mod).ml: $(PP_DEPS)
    cmi = $(if $(not $(file-exists $(mod).mli)), $(mod).cmi)
    $(mod).cmo $(cmi): $(PP_DEPS)
    $(mod).cmx $(mod).o $(cmi): $(PP_DEPS)

This tells OMake that all compilation and dependency-scanning operations
for all your module implementations require the preprocessors to be
built first.  The build should then proceed as required.

HTH,
- Michael



More information about the Omake mailing list