Filenames

This is a reference to the standard filenames and extensions used by various parts of the OCaml build system.

Note: There is an extended mailing list posting about filenames used by OCaml here.

Source and object files

The basic source, object and binary files, with comparisons to C programming:

Purpose C Bytecode Native code
Source code *.c *.ml *.ml
Header files1 *.h *.mli *.mli
Object files *.o *.cmo *.cmx2
Library files *.a *.cma *.cmxa3
Binary programs prog prog prog.opt4

Notes

  1. In C the header files describe the functions, etc., but only by convention. In OCaml, the *.mli file is the exported signature of the module, and the compiler strictly enforces it.
    In most cases for a module called Foo you will find two files: foo.ml and foo.mli. foo.ml is the implementation and foo.mli is the interface or signature.
    Notice also that the first letter of the file is turned to uppercase to get the module name. For example, Extlib contains a file called uTF8.mli which is the signature of a module called UTF8.
  2. There is also a corresponding *.o file which contains the actual machine code, but you can usually ignore this file.
  3. There is also a corresponding *.a file which contains the actual machine code, but you can usually ignore this file.
  4. This is the convention often used by OCaml programs, but in fact you can name binary programs however you want.

*.cmi files

*.cmi files are intermediate files which are compiled forms of the .mli (interface or "header file").

To produce them, just compile the .mli file:

ocamlc -c foo.mli