Previous Contents
Chapter 7 The commands camlp4
Camlp4 is a command which you can type from your shell. It has several versions: camlp4, camlp4o, camlp4r. Actually, the basic command is camlp4, the other ones being shortcuts for this command with syntaxes previously loaded (see man page).

Its options are in two parts: the ``load'' options and the ``other'' options. The input file is among the ``other'' options, generally a .mli interface file or .ml implementation file.

7.1 The load options

The ``load'' options *must* come first. They are a list of OCaml object files (cmo) or library file (cma) which are loaded in camlp4 core before any other operation. These files are found in a path. You can use the option -I to add directories in this path. By default, the path contains only the camlp4 library directory (depending on the installation).

Notice that the current directory is *not* by default in the path: to load a file belonging to the current directory, you have to use either the option -I . or to type the object file prefixed by a dot and a slash.

In fact, the command camlp4 alone, without any load option does nothing with the input file and fails. You need to specify at least one parser and one printer. If you don't specify any parser, you get the message ``Failure: no loaded parsing module'', if you don't specify any printer, ``Failure: no printer''. When it runs, camlp4 applies the parser to the input file, which builds a syntax tree and this syntax tree is printed using the printer.

7.2 The other options

The other options follow. If there is a risk of ambiguities, you can use -- to separate the load options and the other ones: indeed, the other options can be extended by the object files loaded in the core: in particular, the provided object file pr_depend.cmo adds -I among the other options.

To see the list of available options, type camlp4 -help or, since the object files can extend the options, type camlp4 <load-options> -help where <load-options> is your load options. Type, for example, and compare the results:
            camlp4 -help
            camlp4 pa_r.cmo pa_extend.cmo -help
            camlp4 pr_depend.cmo -help
7.3 The predefined object files

The predefined object files, available in the camlp4 library