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
- 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 calledFooyou will find two files:foo.mlandfoo.mli.foo.mlis the implementation andfoo.mliis 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 calleduTF8.mliwhich is the signature of a module calledUTF8. - There is also a corresponding *.o file which contains the actual machine code, but you can usually ignore this file.
- There is also a corresponding *.a file which contains the actual machine code, but you can usually ignore this file.
- 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