Ocamlbuild; top level building

Successfully reorganized my project for ocamlbuild with subdirectories and using ocamlfind it was difficult for me to create a top level.

I built a .mltop file containing all the modules to be included, and added the packages to _tags , but the assembly does not work. He cannot find the C functions compiled with one of the modules. When -classic-display I see this libcside.a file that does not turn on and does not even compile at all! The c file is added as a dependency in myocamlbuild.ml ,

 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 am missing something in setting up the assembly for the top level, but I cannot find a reliable resource on the Internet. Thanks.

+2
source share
1 answer
  • I believe cutil.ml describes the ocaml side of libcside.a - correct?
  • Did you put Cutil in mltop?
  • The ocaml library will not link libcside.a in with your current plugin environment ( dep only instructs ocamlbuild to build it, not a link)
  • Here is a simple (and working) way to create a 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 

    Note that the source C is called linuxnet_c.c , so the resulting object file does not override the value from linuxnet.ml (or vice versa). And finally in _tags:

     true: use_linuxnet 

    With this setting, it will be available in toplevel (note that there is no need to embed Linuxnet in .mltop, because linuxnet.cma will be added to the link using the use_linuxnet flag (generated using ocaml_lib )).

+3
source

Source: https://habr.com/ru/post/956901/


All Articles