OCaml

Ocamlbuild

Project depending on external libraries

If your project depends on the external libraries, you should first install them with opam. Assuming your dependencies are foo and bar and the main entry point of your project is foobar.ml you can then build a bytecode executable with

ocamlbuild -use-ocamlfind -pkgs 'foo,bar' foobar.byte

Warning: the names foo and bar must be the names of the ocamlfind packages, they may differ from the names of the opam packages.

Instead of specifying the packages on the command line, you can create a config file named _tags with the following content

true: package(foo), package(bar)

Basic example with no external dependency

If your project has no external dependency and has foo.ml as its main entry point, you can compile a bytecode version with

ocamlbuild foo.byte

To get a native executable, run

ocamlbuild foo.native

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow