views:

131

answers:

1

Having successfully reorganized my project for ocamlbuild with subdirectories and using ocamlfind, I've found it difficult to build the top-level.

I've constructed a .mltop file containing all the modules that would be included and added the packages to the _tags, but the build doesn't work. It cannot find the C functions that are compiled with one of the modules. With -classic-display on, I can see that file, libcside.a, not being included and isn't even being compiled at all! The c file is added as a dependency in myocamlbuild.ml by,

flag ["link"; "ocaml"; "use_cutil"] (S [A"-cclib"; A"-L."; ]);
dep  ["link"; "ocaml"; "use_cutil"] ["libcside.a"];

and in _tags,

<utilities.*> : use_cutil
<**/*.top> : use_str, use_unix, use_cutil, use_curl, use_mysql

and, finally, in libcside.clib,

cutil.o

I'm missing something in setting up the build for the top level, but I cannot find a reliable resource online. Thanks.

+2  A: 
  • I presume that cutil.ml describes ocaml side of libcside.a - correct?
  • Did you put Cutil in mltop?
  • With your current plugin cutil ocaml library will not link libcside.a in (dep only instructs ocamlbuild to build it, not link)
  • Here is a simple (and working) way to build project-local ocaml library with C stubs. In myocamlbuild.ml:

    ocaml_lib "linuxnet";
    let liblinuxnet_stubs = "liblinuxnet_stubs." ^ !Options.ext_lib in
    flag ["link"; "ocaml"; "use_linuxnet"] (S[A"-cclib"; A liblinuxnet_stubs;]);
    dep  ["link"; "ocaml"; "use_linuxnet"] [liblinuxnet_stubs];
    

    In liblinuxnet_stubs.clib:

    linuxnet_c.o
    

    Notice that the C source is called linuxnet_c.c so that the resulting object file doesn't override the one from linuxnet.ml (or vice versa). And finally in _tags:

    true: use_linuxnet
    

    With this setup it will be available in toplevel (note that there is no need to put Linuxnet into .mltop cause linuxnet.cma will be added to link by use_linuxnet flag (generated with ocaml_lib usage)).

ygrek
1. Utilities does2. yes.3. yes, this did it. thanks. I was had added the A"libcside" to the flags, but it hadn't worked. I was missing ocaml_lib. thanks!
nlucaroni