Question

I'm toying around with OCaml. The first thing I want to know how to do is build an OCaml project. Right now, I just want something stupidly simple since I'm just learning. Could anyone point me towards a build system along with a "hello world" type example for using that build system?

Was it helpful?

Solution

ocamlopt is the standard native-code compiler. Typical build syntax is:

ocamlopt -o execname module1.ml module2.ml

You can use ocamlc to compile to bytecode instead.

Generally the standard library is already included. If you're on a *nix system, and want to include, say, the unix library, you'd do something like

ocamlopt -o execname unix.cmxa module1.ml module2.ml

cmxa files are native code libs, cma files are bytecode libs.

For more complicated builds, theres the ocamlfind program that helps locate libaries. You can also use GNU make and similar tools. More info can be found here. This is a page about using gmake.

This is an ok "Coder's First Ocaml" page.
Here is the lectures page for the Ocaml class I took back in college. Don't try hitting up Professor Gunter for any tips, though, she was an evil troll if memory serves.

OTHER TIPS

There is also ocamlbuild. For the simple project without external dependencies it is as simple as

ocamlbuild prog.native

You're probably looking for an ide. Take a look at Know of an OCAML IDE?.

http://www.ocaml-tutorial.org/compiling_ocaml_projects explains the compilation basics. At the bottom of that page there's a section called Automated build systems and links to the topics Compiling with GNU makeand Compiling with Omake both including samples.

Have a look at ocaml-make by Markus Mottle. The project includes OCamlMakefile. Copy this into your source directory and create a Makefile, e.g.:

SOURCES = hello.ml
RESULT  = hello
-include OCamlMakefile

You probably know this, but just in case you don't, OCaml include a REPL that you can use to code interactively without needing to compile. It can be quite useful when you're first learning.

An up-and-coming project is OASIS, a pretty nifty build system being developed by Sylvain Le Gall. He uses it in a bunch of his OCaml projects, so do I.

I would also add another Makefile for Ocaml, which I use for my projects.

The Makefile and example usage are available on the Ocaml website.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top