Using an external library
From Gallium
Imagine you want to use lablgl and lablglut in your OCaml project. These libraries are not currently directly known by ocamlbuild so you have to declare them. To do so you have to write a plugin.
$ cat myocamlbuild.ml open Ocamlbuild_plugin;; open Command;; dispatch begin function | After_rules -> ocaml_lib ~extern:true ~dir:"+lablGL" "lablgl"; ocaml_lib ~extern:true ~dir:"+lablGL" "lablglut"; | _ -> () end;;
The ocaml_lib declarations are the important part of this plugin. You can reach some documentation about this function in the API documentation. This declaration inform ocamlbuild and produce tags to use the library, they are named use_#{library_name}.
Then you have to specify programs which use these libraries, you can do so using the _tags file.
$ cat _tags # Tag things that are linked with external libraries <main.{byte,native}>: use_lablgl, use_lablglut # Tag also sources that use these libraries. # This will add -I +lablGL. # You can specify something more precise than **/*.ml <**/*.ml>: use_lablgl
$ ocamlbuild main.byte main.native
That's it!
Note: that's also the case when Using internal libraries.