<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14"> <TITLE> The toplevel system (ocaml) </TITLE> </HEAD> <BODY TEXT=black BGCOLOR=white> <A HREF="manual022.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual024.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> <HR> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#2de52d"><DIV ALIGN=center><TABLE> <TR><TD><A NAME="htoc103"><B><FONT SIZE=6>Chapter 9</FONT></B></A></TD> <TD WIDTH="100%" ALIGN=center><B><FONT SIZE=6>The toplevel system (ocaml)</FONT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="c:camllight"></A> <BR> This chapter describes the toplevel system for Objective Caml, that permits interactive use of the Objective Caml system through a read-eval-print loop. In this mode, the system repeatedly reads Caml phrases from the input, then typechecks, compile and evaluate them, then prints the inferred type and result value, if any. The system prints a <TT>#</TT> (sharp) prompt before reading each phrase.<BR> <BR> Input to the toplevel can span several lines. It is terminated by <TT>;;</TT> (a double-semicolon). The toplevel input consists in one or several toplevel phrases, with the following syntax:<BR> <DIV ALIGN=center><TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD ALIGN=right NOWRAP> <TT><I><FONT COLOR=maroon>toplevel-input</FONT></I></TT></TD> <TD ALIGN=right NOWRAP>::=</TD> <TD ALIGN=left NOWRAP> { <TT><I><FONT COLOR=maroon>toplevel-phrase</FONT></I></TT> } <TT><FONT COLOR=blue>;;</FONT></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> <TT><I><FONT COLOR=maroon>toplevel-phrase</FONT></I></TT></TD> <TD ALIGN=right NOWRAP>::=</TD> <TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>definition</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> </TD> <TD ALIGN=right NOWRAP>|</TD> <TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>expr</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> </TD> <TD ALIGN=right NOWRAP>|</TD> <TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>#</FONT></TT> <TT><I><FONT COLOR=maroon>ident</FONT></I></TT> <TT><I><FONT COLOR=maroon>directive-argument</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> <TT><I><FONT COLOR=maroon>definition</FONT></I></TT></TD> <TD ALIGN=right NOWRAP>::=</TD> <TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>let</FONT></TT> [<TT><FONT COLOR=blue>rec</FONT></TT>] <TT><I><FONT COLOR=maroon>let-binding</FONT></I></TT> { <TT><FONT COLOR=blue>and</FONT></TT> <TT><I><FONT COLOR=maroon>let-binding</FONT></I></TT> }</TD> </TR> <TR><TD ALIGN=right NOWRAP> </TD> <TD ALIGN=right NOWRAP>|</TD> <TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>external</FONT></TT> <TT><I><FONT COLOR=maroon>value-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> <TT><I><FONT COLOR=maroon>external-declaration</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> </TD> <TD ALIGN=right NOWRAP>|</TD> <TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>type-definition</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> </TD> <TD ALIGN=right NOWRAP>|</TD> <TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>exception-definition</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> </TD> <TD ALIGN=right NOWRAP>|</TD> <TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>module</FONT></TT> <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT> [ <TT><FONT COLOR=blue>:</FONT></TT> <TT><I><FONT COLOR=maroon>module-type</FONT></I></TT> ] <TT><FONT COLOR=blue>=</FONT></TT> <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> </TD> <TD ALIGN=right NOWRAP>|</TD> <TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>module</FONT></TT> <TT><FONT COLOR=blue>type</FONT></TT> <TT><I><FONT COLOR=maroon>modtype-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> <TT><I><FONT COLOR=maroon>module-type</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> </TD> <TD ALIGN=right NOWRAP>|</TD> <TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>open</FONT></TT> <TT><I><FONT COLOR=maroon>module-path</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> <TT><I><FONT COLOR=maroon>directive-argument</FONT></I></TT></TD> <TD ALIGN=right NOWRAP>::=</TD> <TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>nothing</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> </TD> <TD ALIGN=right NOWRAP>|</TD> <TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>string-literal</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> </TD> <TD ALIGN=right NOWRAP>|</TD> <TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>integer-literal</FONT></I></TT></TD> </TR> <TR><TD ALIGN=right NOWRAP> </TD> <TD ALIGN=right NOWRAP>|</TD> <TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>value-path</FONT></I></TT></TD> </TR></TABLE></DIV><BR> A phrase can consist of a definition, similar to those found in implementations of compilation units or in <TT><FONT COLOR=blue>struct</FONT></TT> ... <TT><FONT COLOR=blue>end</FONT></TT> module expressions. The definition can bind value names, type names, an exception, a module name, or a module type name. The toplevel system performs the bindings, then prints the types and values (if any) for the names thus defined.<BR> <BR> A phrase may also consist in a <TT>open</TT> directive (see section <A HREF="manual019.html#s:module-expr">6.11</A>), or a value expression (section <A HREF="manual015.html#s:value-expr">6.7</A>). Expressions are simply evaluated, without performing any bindings, and the value of the expression is printed.<BR> <BR> Finally, a phrase can also consist in a toplevel directive, starting with <TT>#</TT> (the sharp sign). These directives control the behavior of the toplevel; they are listed below in section <A HREF="#s:toplevel-directives">9.2</A>.<BR> <BR> <FONT COLOR=purple>Unix:</FONT> <BLOCKQUOTE> The toplevel system is started by the command <TT>ocaml</TT>, as follows: <PRE> ocaml <I>options</I> <I>objects</I> # interactive mode ocaml <I>options</I> <I>objects</I> <I>scriptfile</I> # script mode </PRE> <I>options</I> are described below. <I>objects</I> are filenames ending in <TT>.cmo</TT> or <TT>.cma</TT>; they are loaded into the interpreter immediately after <I>options</I> are set. <I>scriptfile</I> is any file name not ending in <TT>.cmo</TT> or <TT>.cma</TT>.<BR> <BR> If no <I>scriptfile</I> is given on the command line, the toplevel system enters interactive mode: phrases are read on standard input, results are printed on standard output, errors on standard error. End-of-file on standard input terminates <TT>ocaml</TT> (see also the <TT>#quit</TT> directive in section <A HREF="#s:toplevel-directives">9.2</A>).<BR> <BR> On start-up (before the first phrase is read), if the file <TT>.ocamlinit</TT> exists in the current directory, its contents are read as a sequence of Objective Caml phrases and executed as per the <TT>#use</TT> directive described in section <A HREF="#s:toplevel-directives">9.2</A>. The evaluation outcode for each phrase are not displayed.<BR> <BR> The toplevel system does not perform line editing, but it can easily be used in conjunction with an external line editor such as <TT>fep</TT>; just run <TT>fep -emacs ocaml</TT> or <TT>fep -vi ocaml</TT>. Another option is to use <TT>ocaml</TT> under Gnu Emacs, which gives the full editing power of Emacs (see the subdirectory <TT>emacs</TT> of the Objective Caml distribution).<BR> <BR> At any point, the parsing, compilation or evaluation of the current phrase can be interrupted by pressing <TT>ctrl-C</TT> (or, more precisely, by sending the <TT>sigintr</TT> signal to the <TT>ocaml</TT> process). The toplevel then immediately returns to the <TT>#</TT> prompt.<BR> <BR> If <I>scriptfile</I> is given on the command-line to <TT>ocaml</TT>, the toplevel system enters script mode: the contents of the file are read as a sequence of Objective Caml phrases and executed, as per the <TT>#use</TT> directive (section <A HREF="#s:toplevel-directives">9.2</A>). The outcome of the evaluation is not printed. On reaching the end of file, the <TT>ocaml</TT> command exits immediately. No commands are read from standard input. <TT>Sys.argv</TT> is transformed, ignoring all Objective Caml parameters, and starting with the script file name in <TT>Sys.argv.(0)</TT>.<BR> <BR> In script mode, the first line of the script is ignored if it starts with <TT>#!</TT>. Thus, it is theoretically possible to make the script itself executable and put as first line <TT>#!/usr/local/bin/ocaml</TT>, thus calling the toplevel system automatically when the script is run. However, <TT>ocaml</TT> itself is a <TT>#!</TT> script on most installations of Objective Caml, and Unix kernels usually do not handle nested <TT>#!</TT> scripts.</BLOCKQUOTE> <FONT COLOR=purple>Windows:</FONT> <BLOCKQUOTE> In addition to the text-only command <TT>ocaml.exe</TT>, which works exactly as under Unix (see above), a graphical user interface for the toplevel is available under the name <TT>ocamlwin.exe</TT>. It should be launched from the Windows file manager or program manager.<BR> <BR> The ``Terminal'' windows is split in two panes. Phrases are entered and edited in the bottom pane. The top pane displays a copy of the input phrases as they are processed by the Objective Caml toplevel, interspersed with the toplevel responses. The ``Return'' key sends the contents of the bottom pane to the Objective Caml toplevel. The ``Enter'' key inserts a newline without sending the contents of the Input window. (This can be configured with the ``Preferences'' menu item.)<BR> <BR> The contents of the input window can be edited at all times, with the standard Windows interface. An history of previously entered phrases is maintained and displayed in a separate window.<BR> <BR> To quit the <TT>Camlwin</TT> application, either select ``Quit'' from the ``File'' menu, or use the <TT>quit</TT> function described below.<BR> <BR> At any point, the parsing, compilation or evaluation of the current phrase can be interrupted by selecting the ``Interrupt Objective Caml'' menu item. This goes back to the <TT>#</TT> prompt. </BLOCKQUOTE> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE> <TR><TD><A NAME="htoc104"><B><FONT SIZE=5>9.1</FONT></B></A></TD> <TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5>Options</FONT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="s:toplevel-options"></A><BR> The following command-line options are recognized by the <TT>ocaml</TT> command. <DL COMPACT=compact><DT><B><TT>-I</TT> <I>directory</I></B><DD> Add the given directory to the list of directories searched for source and compiled files. By default, the current directory is searched first, then the standard library directory. Directories added with <TT>-I</TT> are searched after the current directory, in the order in which they were given on the command line, but before the standard library directory.<BR> <BR> If the given directory starts with <TT>+</TT>, it is taken relative to the standard library directory. For instance, <TT>-I +labltk</TT> adds the subdirectory <TT>labltk</TT> of the standard library to the search path.<BR> <BR> Directories can also be added to the search path once the toplevel is running with the <TT>#directory</TT> directive (section <A HREF="#s:toplevel-directives">9.2</A>).<BR> <BR> <DT><B><TT>-nolabels</TT></B><DD> Ignore non-optional labels in types. Labels cannot be used in applications, and parameter order becomes strict.<BR> <BR> <DT><B><TT>-principal</TT></B><DD> Check information path during type-checking, to make sure that all types are derived in a principal way. All programs accepted in <TT>-principal</TT> mode are also accepted in default mode with equivalent types.<BR> <BR> <DT><B><TT>-rectypes</TT></B><DD> Allow arbitrary recursive types during type-checking. By default, only recursive types where the recursion goes through an object type are supported.<BR> <BR> <DT><B><TT>-unsafe</TT></B><DD> See the corresponding option for <TT>ocamlc</TT>, chapter <A HREF="manual022.html#c:camlc">8</A>. Turn bound checking off on array and string accesses (the <TT>v.(i)</TT> and <TT>s.[i]</TT> constructs). Programs compiled with <TT>-unsafe</TT> are therefore slightly faster, but unsafe: anything can happen if the program accesses an array or string outside of its bounds.<BR> <BR> <DT><B><TT>-w</TT> <I>warning-list</I></B><DD> Enable or disable warnings according to the argument <I>warning-list</I>.</DL> <FONT COLOR=purple>Unix:</FONT> <BLOCKQUOTE> The following environment variables are also consulted: <DL COMPACT=compact><DT> <B><TT>LC_CTYPE</TT></B><DD> If set to <TT>iso_8859_1</TT>, accented characters (from the ISO Latin-1 character set) in string and character literals are printed as is; otherwise, they are printed as decimal escape sequences (<TT>\</TT><I>ddd</I>).<BR> <BR> <DT><B><TT>TERM</TT></B><DD> When printing error messages, the toplevel system attempts to underline visually the location of the error. It consults the <TT>TERM</TT> variable to determines the type of output terminal and look up its capabilities in the terminal database. </DL> </BLOCKQUOTE> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE> <TR><TD><A NAME="htoc105"><B><FONT SIZE=5>9.2</FONT></B></A></TD> <TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5>Toplevel directives</FONT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="s:toplevel-directives"></A><BR> The following directives control the toplevel behavior, load files in memory, and trace program execution.<BR> <BR> <B>Note:</B> all directives start with a <TT>#</TT> (sharp) symbol. This <TT>#</TT> must be typed before the directive, and must not be confused with the <TT>#</TT> prompt displayed by the interactive loop. For instance, typing <TT>#quit;;</TT> will exit the toplevel loop, but typing <TT>quit;;</TT> will result in an ``unbound value <TT>quit</TT>'' error. <DL COMPACT=compact><DT><B><TT>#quit;;</TT></B><DD> Exit the toplevel loop and terminate the <TT>ocaml</TT> command.<BR> <BR> <DT><B><TT>#labels </TT><I>bool</I></B><B><TT>;;</TT></B><DD> Ignore labels in function types if argument is <TT>false</TT>, or switch back to default behaviour (commuting style) if argument is <TT>true</TT>.<BR> <BR> <DT><B><TT>#warnings "</TT><I>warning-list</I></B><B><TT>";;</TT></B><DD> Enable or disable warnings according to the argument.<BR> <BR> <DT><B><TT>#directory "</TT><I>dir-name</I></B><B><TT>";;</TT></B><DD> Add the given directory to the list of directories searched for source and compiled files.<BR> <BR> <DT><B><TT>#cd "</TT><I>dir-name</I></B><B><TT>";;</TT></B><DD> Change the current working directory.<BR> <BR> <DT><B><TT>#load "</TT><I>file-name</I></B><B><TT>";;</TT></B><DD> Load in memory a bytecode object file (<TT>.cmo</TT> file) produced by the batch compiler <TT>ocamlc</TT>.<BR> <BR> <DT><B><TT>#use "</TT><I>file-name</I></B><B><TT>";;</TT></B><DD> Read, compile and execute source phrases from the given file. This is textual inclusion: phrases are processed just as if they were typed on standard input. The reading of the file stops at the first error encountered.<BR> <BR> <DT><B><TT>#install_printer </TT><I>printer-name</I></B><B><TT>;;</TT></B><DD> This directive registers the function named <I>printer-name</I> (a value path) as a printer for values whose types match the argument type of the function. That is, the toplevel loop will call <I>printer-name</I> when it has such a value to print.<BR> <BR> The printing function <I>printer-name</I> should have type <TT><FONT COLOR=blue>Format.formatter</FONT></TT> <TT><FONT COLOR=blue>-></FONT></TT> <TT><I><FONT COLOR=maroon>t</FONT></I></TT> <TT><FONT COLOR=blue>-></FONT></TT> <TT><FONT COLOR=blue>unit</FONT></TT>, where <I>t</I> is the type for the values to be printed, and should output its textual representation for the value of type <I>t</I> on the given formatter, using the functions provided by the <TT>Format</TT> library. For backward compatibility, <I>printer-name</I> can also have type <TT><I><FONT COLOR=maroon>t</FONT></I></TT> <TT><FONT COLOR=blue>-></FONT></TT> <TT><FONT COLOR=blue>unit</FONT></TT> and should then output on the standard formatter, but this usage is deprecated.<BR> <BR> <DT><B><TT>#remove_printer </TT><I>printer-name</I></B><B><TT>;;</TT></B><DD> Remove the named function from the table of toplevel printers.<BR> <BR> <DT><B><TT>#trace </TT><I>function-name</I></B><B><TT>;;</TT></B><DD> After executing this directive, all calls to the function named <I>function-name</I> will be ``traced''. That is, the argument and the result are displayed for each call, as well as the exceptions escaping out of the function, raised either by the function itself or by another function it calls. If the function is curried, each argument is printed as it is passed to the function.<BR> <BR> <DT><B><TT>#untrace </TT><I>function-name</I></B><B><TT>;;</TT></B><DD> Stop tracing the given function.<BR> <BR> <DT><B><TT>#untrace_all;;</TT></B><DD> Stop tracing all functions traced so far.<BR> <BR> <DT><B><TT>#print_depth </TT><I>n</I></B><B><TT>;;</TT></B><DD> Limit the printing of values to a maximal depth of <I>n</I>. The parts of values whose depth exceeds <I>n</I> are printed as <TT>...</TT> (ellipsis).<BR> <BR> <DT><B><TT>#print_length </TT><I>n</I></B><B><TT>;;</TT></B><DD> Limit the number of value nodes printed to at most <I>n</I>. Remaining parts of values are printed as <TT>...</TT> (ellipsis).</DL> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE> <TR><TD><A NAME="htoc106"><B><FONT SIZE=5>9.3</FONT></B></A></TD> <TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5>The toplevel and the module system</FONT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="s:toplevel-modules"></A><BR> Toplevel phrases can refer to identifiers defined in compilation units with the same mechanisms as for separately compiled units: either by using qualified names (<TT>Modulename.localname</TT>), or by using the <TT>open</TT> construct and unqualified names (see section <A HREF="manual011.html#s:names">6.3</A>).<BR> <BR> However, before referencing another compilation unit, an implementation of that unit must be present in memory. At start-up, the toplevel system contains implementations for all the modules in the the standard library. Implementations for user modules can be entered with the <TT>#load</TT> directive described above. Referencing a unit for which no implementation has been provided results in the error ``Reference to undefined global `...' ''.<BR> <BR> Note that entering <TT>open </TT><I>mod</I> merely accesses the compiled interface (<TT>.cmi</TT> file) for <I>mod</I>, but does not load the implementation of <I>mod</I>, and does not cause any error if no implementation of <I>mod</I> has been loaded. The error ``reference to undefined global <I>mod</I>'' will occur only when executing a value or module definition that refers to <I>mod</I>.<BR> <BR> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE> <TR><TD><A NAME="htoc107"><B><FONT SIZE=5>9.4</FONT></B></A></TD> <TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5>Common errors</FONT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE><BR> This section describes and explains the most frequently encountered error messages. <DL COMPACT=compact><DT><B>Cannot find file <I>filename</I></B><DD> The named file could not be found in the current directory, nor in the directories of the search path. <BR> <BR> If <I>filename</I> has the format <I>mod</I><TT>.cmi</TT>, this means you have referenced the compilation unit <I>mod</I>, but its compiled interface could not be found. Fix: compile <I>mod</I><TT>.mli</TT> or <I>mod</I><TT>.ml</TT> first, to create the compiled interface <I>mod</I><TT>.cmi</TT>.<BR> <BR> If <I>filename</I> has the format <I>mod</I><TT>.cmo</TT>, this means you are trying to load with <TT>#load</TT> a bytecode object file that does not exist yet. Fix: compile <I>mod</I><TT>.ml</TT> first.<BR> <BR> If your program spans several directories, this error can also appear because you haven't specified the directories to look into. Fix: use the <TT>#directory</TT> directive to add the correct directories to the search path.<BR> <BR> <DT><B>This expression has type <I>t</I></B><SUB><B><FONT SIZE=2>1</FONT></B></SUB><B>, but is used with type <I>t</I></B><SUB><B><FONT SIZE=2>2</FONT></B></SUB><DD> See section <A HREF="manual022.html#s:comp-errors">8.4</A>.<BR> <BR> <DT><B>Reference to undefined global <I>mod</I></B><DD> You have neglected to load in memory an implementation for a module with <TT>#load</TT>. See section <A HREF="#s:toplevel-modules">9.3</A> above.</DL> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE> <TR><TD><A NAME="htoc108"><B><FONT SIZE=5>9.5</FONT></B></A></TD> <TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5>Building custom toplevel systems: <TT>ocamlmktop</TT></FONT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE><BR> The <TT>ocamlmktop</TT> command builds Objective Caml toplevels that contain user code preloaded at start-up. <BR> <BR> The <TT>ocamlmktop</TT> command takes as argument a set of <TT>.cmo</TT> and <TT>.cma</TT> files, and links them with the object files that implement the Objective Caml toplevel. The typical use is: <PRE> ocamlmktop -o mytoplevel foo.cmo bar.cmo gee.cmo </PRE>This creates the bytecode file <TT>mytoplevel</TT>, containing the Objective Caml toplevel system, plus the code from the three <TT>.cmo</TT> files. This toplevel is directly executable and is started by: <PRE> ./mytoplevel </PRE>This enters a regular toplevel loop, except that the code from <TT>foo.cmo</TT>, <TT>bar.cmo</TT> and <TT>gee.cmo</TT> is already loaded in memory, just as if you had typed: <PRE> #load "foo.cmo";; #load "bar.cmo";; #load "gee.cmo";; </PRE>on entrance to the toplevel. The modules <TT>Foo</TT>, <TT>Bar</TT> and <TT>Gee</TT> are not opened, though; you still have to do <PRE> open Foo;; </PRE>yourself, if this is what you wish.<BR> <BR> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE> <TR><TD><A NAME="htoc109"><B><FONT SIZE=5>9.6</FONT></B></A></TD> <TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5>Options</FONT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE><BR> The following command-line options are recognized by <TT>ocamlmktop</TT>. <DL COMPACT=compact><DT><B><TT>-cclib</TT> <I>libname</I></B><DD> Pass the <TT>-l</TT><I>libname</I> option to the C linker when linking in ``custom runtime'' mode. See the corresponding option for <TT>ocamlc</TT>, in chapter <A HREF="manual022.html#c:camlc">8</A>.<BR> <BR> <DT><B><TT>-ccopt</TT> <I>option</I></B><DD> Pass the given option to the C compiler and linker, when linking in ``custom runtime'' mode. See the corresponding option for <TT>ocamlc</TT>, in chapter <A HREF="manual022.html#c:camlc">8</A>.<BR> <BR> <DT><B><TT>-custom</TT></B><DD> Link in ``custom runtime'' mode. See the corresponding option for <TT>ocamlc</TT>, in chapter <A HREF="manual022.html#c:camlc">8</A>.<BR> <BR> <DT><B><TT>-I</TT> <I>directory</I></B><DD> Add the given directory to the list of directories searched for compiled object code files (<TT>.cmo</TT> and <TT>.cma</TT>).<BR> <BR> <DT><B><TT>-o</TT> <I>exec-file</I></B><DD> Specify the name of the toplevel file produced by the linker. The default is <TT>a.out</TT>.</DL> <HR> <A HREF="manual022.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual024.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> </BODY> </HTML>