Version française
Home     About     Download     Resources     Contact us    
Browse thread
ocamlbuild and c libraries
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andrew Warshaver <awarshaver@j...>
Subject: ocamlbuild and c libraries
For the most part I tried to follow Nicolas's example on the previous 
thread with similar name, but unfortunately I get an error that I do not 
entirely understand.

My target is intern/live_query/live_query.native.  It uses an ocaml/c 
library called jane that lives in janebase/lb (thanks Nicolas, for the 
renaming tip).  In there exists a jane.mlpack, and a libjane.clib.  Also 
there is a couple of _tags file:

$ cat janebase/lb/_tags
<*.cmx>: for-pack(Jane)
<*.cmo>: for-pack(Jane)
<jane.cmx>: -for-pack(Jane)
<jane.cmo>: -for-pack(Jane)
<cephes>: include
<jane.cm{x,}a>: use_libjane

$ cat intern/live_query/_tags
<{single,live}_query.{byte,native}>: use_jane (i also tried 
include_jane, this results in a different error message; in fact the 
same error if I omit this _tags altogether, it says undefined references 
in jane.o)

Also, myocamlbuild.ml :

$ cat myocamlbuild.ml
open Ocamlbuild_plugin;;
open Command;;

let packages = "bigarray,pcre,res,netstring"

let headers = ["janebase/lb/cephes/mconf.h"; 
"janebase/lb/cephes/protos.h"];;

let ocamlfind cmd =
   S [A "ocamlfind"; A cmd; A "-package"; A packages;
      A "-I"; A "+camlp4"; A "-pp"; A "camlp4orf";
      A "-pp"; A "camlp4o /home/awarshaver/multi-oc/lib/pa_type_conv.cmo 
/home/awarshaver/multi-oc/lib/pa_sexp_conv.cmo"];;

flag ["ocaml"; "compile"] (A"-thread");;
flag ["ocaml"; "link"; "program"] (S[A"-linkpkg"; A"-thread"]);;

dispatch begin function
   | After_options ->
       Options.ocamlc := ocamlfind "c";
       Options.ocamlopt := ocamlfind "opt";
       Options.ocamldep := ocamlfind "dep";
   | After_rules ->
       ocaml_lib "jane";

       flag ["link"; "library"; "ocaml"; "byte"; "use_libjane"]
         (S[A"-dllib"; A"-ljane"; A"-cclib"; A"-ljane"]);

       flag ["link"; "library"; "ocaml"; "native"; "use_libjane"]
         (S[A"-cclib"; A"-ljane"]);

       dep ["link"; "ocaml"; "use_libjane"] ["janebase/lb/libjane.a"];

       dep ["compile"; "c"] headers;
   | _ -> ()
end

I can build the library ok...

$ ocamlbuild janebase/lb/jane.cmxa
+ ocamlfind c -package bigarray,pcre,res,netstring -I +camlp4 -pp 
camlp4orf -pp 'camlp4o /home/awarshaver/multi-oc/lib/pa_type_conv.cmo 
/home/awarshaver/multi-oc/lib/pa_sexp_conv.cmo' -c janebase/lb/cephes/main.c
janebase/lb/cephes/main.c: In function ‘main’:
janebase/lb/cephes/main.c:9: warning: control reaches end of non-void 
function
Finished, 286 targets (0 cached) in 00:01:12.

But not my target..

$ ocamlbuild intern/live_query/live_query.native
Solver failed:
   Ocamlbuild knows of no rules that apply to a target named jane.cmx. 
This can happen if you ask Ocamlbuild to build a target with the wrong 
extension (e.g. .opt instead of .native) or if the source files live in 
directories that have not been specified as include directories.
Backtrace:
   - Failed to build the target intern/live_query/live_query.native
       - Building intern/live_query/live_query.native:
           - Building jane.a:
               - Failed to build all of these:
                   - Building jane.cmx
                   - Building jane.mllib
Compilation unsuccessful after building 358 targets (358 cached) in 
00:00:28.

Insights appreciated!

Thanks,
Andrew