|
Packit |
b513ef |
|
|
Packit |
b513ef |
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>Toploops and runtime systems
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
NAME="GENERATOR"
|
|
Packit |
b513ef |
CONTENT="Modular DocBook HTML Stylesheet Version 1.79">
|
|
Packit |
b513ef |
REL="HOME"
|
|
Packit |
b513ef |
TITLE="The findlib User's Guide"
|
|
Packit |
b513ef |
HREF="index.html">
|
|
Packit |
b513ef |
REL="UP"
|
|
Packit |
b513ef |
TITLE="A new frontend for ocamlc"
|
|
Packit |
b513ef |
HREF="c192.html">
|
|
Packit |
b513ef |
REL="PREVIOUS"
|
|
Packit |
b513ef |
TITLE="A new frontend for ocamlc"
|
|
Packit |
b513ef |
HREF="c192.html">
|
|
Packit |
b513ef |
REL="NEXT"
|
|
Packit |
b513ef |
TITLE="Multi-threaded applications"
|
|
Packit |
b513ef |
HREF="x265.html">
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="SECT1"
|
|
Packit |
b513ef |
BGCOLOR="#FFFFFF"
|
|
Packit |
b513ef |
TEXT="#000000"
|
|
Packit |
b513ef |
LINK="#0000FF"
|
|
Packit |
b513ef |
VLINK="#840084"
|
|
Packit |
b513ef |
ALINK="#0000FF"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="NAVHEADER"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
SUMMARY="Header navigation table"
|
|
Packit |
b513ef |
WIDTH="100%"
|
|
Packit |
b513ef |
BORDER="0"
|
|
Packit |
b513ef |
CELLPADDING="0"
|
|
Packit |
b513ef |
CELLSPACING="0"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
COLSPAN="3"
|
|
Packit |
b513ef |
ALIGN="center"
|
|
Packit |
b513ef |
>The findlib User's Guide
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
WIDTH="10%"
|
|
Packit |
b513ef |
ALIGN="left"
|
|
Packit |
b513ef |
VALIGN="bottom"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
HREF="c192.html"
|
|
Packit |
b513ef |
ACCESSKEY="P"
|
|
Packit |
b513ef |
>Prev
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
WIDTH="80%"
|
|
Packit |
b513ef |
ALIGN="center"
|
|
Packit |
b513ef |
VALIGN="bottom"
|
|
Packit |
b513ef |
>Chapter 4. A new frontend for ocamlc
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
WIDTH="10%"
|
|
Packit |
b513ef |
ALIGN="right"
|
|
Packit |
b513ef |
VALIGN="bottom"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
HREF="x265.html"
|
|
Packit |
b513ef |
ACCESSKEY="N"
|
|
Packit |
b513ef |
>Next
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
ALIGN="LEFT"
|
|
Packit |
b513ef |
WIDTH="100%">
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="SECT1"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="SECT1"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
NAME="AEN231"
|
|
Packit |
b513ef |
>Toploops and runtime systems
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="SECT2"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="SECT2"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
NAME="AEN233"
|
|
Packit |
b513ef |
>Dynamic toploops
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>Recent versions of O'Caml support dynamic loading of stub libraries
|
|
Packit |
b513ef |
(but only for the more widely used operating systems). This means
|
|
Packit |
b513ef |
that one can start a toploop by running
|
|
Packit |
b513ef |
|
|
Packit |
b513ef |
|
|
Packit |
b513ef |
CLASS="PROGRAMLISTING"
|
|
Packit |
b513ef |
>$ ocaml
|
|
Packit |
b513ef |
Objective Caml version 3.07+2
|
|
Packit |
b513ef |
|
|
Packit |
b513ef |
# _
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
|
|
Packit |
b513ef |
and that it is now possible to load .cma archive files referring to
|
|
Packit |
b513ef |
shared C libraries ("DLLs"). In older versions of O'Caml this was
|
|
Packit |
b513ef |
not possible and one had to create a so-called custom toploop
|
|
Packit |
b513ef |
with the ocamlmktop command. This method is still supported and
|
|
Packit |
b513ef |
explained below; however, nowadays it is often not necessary to
|
|
Packit |
b513ef |
do so. For the modern way, findlib includes a small script called
|
|
Packit |
b513ef |
"topfind" (i.e. "ocamlfind for the toploop") that can be directly
|
|
Packit |
b513ef |
loaded into the toploop:
|
|
Packit |
b513ef |
|
|
Packit |
b513ef |
|
|
Packit |
b513ef |
CLASS="PROGRAMLISTING"
|
|
Packit |
b513ef |
># #use "topfind";;
|
|
Packit |
b513ef |
- : unit = ()
|
|
Packit |
b513ef |
Findlib has been successfully loaded. Additional directives:
|
|
Packit |
b513ef |
#require "package";; to load a package
|
|
Packit |
b513ef |
#list;; to list the available packages
|
|
Packit |
b513ef |
#camlp4o;; to load camlp4 (standard syntax)
|
|
Packit |
b513ef |
#camlp4r;; to load camlp4 (revised syntax)
|
|
Packit |
b513ef |
#predicates "p,q,...";; to set these predicates
|
|
Packit |
b513ef |
Topfind.reset();; to force that packages will be reloaded
|
|
Packit |
b513ef |
#thread;; to enable threads
|
|
Packit |
b513ef |
|
|
Packit |
b513ef |
- : unit = ()
|
|
Packit |
b513ef |
# _
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>A number of additional directives are now available. The "#require"
|
|
Packit |
b513ef |
directive loads additional packages (with all dependencies):
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="PROGRAMLISTING"
|
|
Packit |
b513ef |
># #require "q1,q2,...,qM";;
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>"#require" loads the listed packages and all their ancestors in the
|
|
Packit |
b513ef |
right order, but leaves packages out that have already been loaded.
|
|
Packit |
b513ef |
Scripts can now simply load and document which packages are used by a
|
|
Packit |
b513ef |
"#require" directive right at the beginning of the script.
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>The #list directive lists the available packages as "ocamlfind list"
|
|
Packit |
b513ef |
would do it.
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>If you need additional predicates, you can set them with #predicates.
|
|
Packit |
b513ef |
Note that this should be done before the first package is loaded in
|
|
Packit |
b513ef |
order to ensure a consistent library system.
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>The #thread directive enables multi-threading if possible. Note that
|
|
Packit |
b513ef |
this is only supported for installations basing on the POSIX thread
|
|
Packit |
b513ef |
library. (However, if you have only have VM threads, you can still
|
|
Packit |
b513ef |
create a custom toploop supporting threads. See below.) Furthermore,
|
|
Packit |
b513ef |
the #thread directive should be executed before any packages are
|
|
Packit |
b513ef |
loaded.
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>The #camlp4o and #camlp4r directives load the camlp4 syntax parsers
|
|
Packit |
b513ef |
for the standard and the revised syntax, respectively.
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>Especially when developing packages, it is sometimes necessary to
|
|
Packit |
b513ef |
reload all dynamically loaded packages in the toploop. This can be
|
|
Packit |
b513ef |
forced by
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="PROGRAMLISTING"
|
|
Packit |
b513ef |
>Topfind.reset();;
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>which causes the "#require" directive to load all packages again. The
|
|
Packit |
b513ef |
Topfind module implements all the mentioned directives.
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="SECT2"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="SECT2"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
NAME="AEN248"
|
|
Packit |
b513ef |
>Custom toploops
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>It is very simple to create toploops. In order to make a toploop
|
|
Packit |
b513ef |
executable that includes directly the packages p1,p2,..,pN simply
|
|
Packit |
b513ef |
execute the command
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="PROGRAMLISTING"
|
|
Packit |
b513ef |
>ocamlfind ocamlmktop -o toploop -package p1,p2,...,pN,findlib -linkpkg
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>(Maybe you have to add the -custom switch.) Note that one of the
|
|
Packit |
b513ef |
packages should be "findlib" itself, because this adds the
|
|
Packit |
b513ef |
additional directives mentioned above, i.e. you can directly use
|
|
Packit |
b513ef |
these directives without #use "topfind" (but running "topfind"
|
|
Packit |
b513ef |
is harmless).
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>Note that such a toploop includes the code of the packages given
|
|
Packit |
b513ef |
on the commmand line, but that it does not automatically add the
|
|
Packit |
b513ef |
package directories to the search path (in previous versions of
|
|
Packit |
b513ef |
findlib this was tried, but it never really worked). To do so,
|
|
Packit |
b513ef |
you still have to #require the packages.
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>In order to create a toploop supporting VM-style threads, use the
|
|
Packit |
b513ef |
command
|
|
Packit |
b513ef |
|
|
Packit |
b513ef |
|
|
Packit |
b513ef |
CLASS="PROGRAMLISTING"
|
|
Packit |
b513ef |
>ocamlfind ocamlmktop -o toploop -package p1,p2,...,pN,findlib,threads -vmthread -linkpkg
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
|
|
Packit |
b513ef |
Now the #thread directive will work and enable the access to the
|
|
Packit |
b513ef |
multi-threading modules.
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="SECT2"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="SECT2"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
NAME="AEN256"
|
|
Packit |
b513ef |
>Runtime systems
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>Building of runtime systems is supported, too. For example, you can run
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="PROGRAMLISTING"
|
|
Packit |
b513ef |
>ocamlfind ocamlc -o runtime -make-runtime -package p1,p2,...,pN -linkpkg
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>but the problem is which options to specify when a program is linked
|
|
Packit |
b513ef |
for this runtime system. If you executed
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="PROGRAMLISTING"
|
|
Packit |
b513ef |
>ocamlfind ocamlc -o program -use-runtime runtime -package p1,p2,...,pN\
|
|
Packit |
b513ef |
-linkpkg m1.cmo ... mM.cmo
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>it would be tried to link the archives from the packages again into
|
|
Packit |
b513ef |
the bytecode binary. Because of this, it is necessary to suppress
|
|
Packit |
b513ef |
linking in packages of the runtime system when linking binaries for a
|
|
Packit |
b513ef |
runtime system. The -dontlink option can be used for this:
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="PROGRAMLISTING"
|
|
Packit |
b513ef |
>ocamlfind ocamlc -o program -use-runtime runtime -package p1,p2,...,pN\
|
|
Packit |
b513ef |
-dontlink p1,p2,...,pN -linkpkg m1.cmo ... mM.cmo
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>Note that the -package option can enumerate more packages than
|
|
Packit |
b513ef |
-dontlink, and in this case the additional packages are actually
|
|
Packit |
b513ef |
linked in as they are not contained in the runtime system.
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
CLASS="NAVFOOTER"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
ALIGN="LEFT"
|
|
Packit |
b513ef |
WIDTH="100%">
|
|
Packit |
b513ef |
SUMMARY="Footer navigation table"
|
|
Packit |
b513ef |
WIDTH="100%"
|
|
Packit |
b513ef |
BORDER="0"
|
|
Packit |
b513ef |
CELLPADDING="0"
|
|
Packit |
b513ef |
CELLSPACING="0"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
WIDTH="33%"
|
|
Packit |
b513ef |
ALIGN="left"
|
|
Packit |
b513ef |
VALIGN="top"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
HREF="c192.html"
|
|
Packit |
b513ef |
ACCESSKEY="P"
|
|
Packit |
b513ef |
>Prev
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
WIDTH="34%"
|
|
Packit |
b513ef |
ALIGN="center"
|
|
Packit |
b513ef |
VALIGN="top"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
HREF="index.html"
|
|
Packit |
b513ef |
ACCESSKEY="H"
|
|
Packit |
b513ef |
>Home
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
WIDTH="33%"
|
|
Packit |
b513ef |
ALIGN="right"
|
|
Packit |
b513ef |
VALIGN="top"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
HREF="x265.html"
|
|
Packit |
b513ef |
ACCESSKEY="N"
|
|
Packit |
b513ef |
>Next
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
WIDTH="33%"
|
|
Packit |
b513ef |
ALIGN="left"
|
|
Packit |
b513ef |
VALIGN="top"
|
|
Packit |
b513ef |
>A new frontend for ocamlc
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
WIDTH="34%"
|
|
Packit |
b513ef |
ALIGN="center"
|
|
Packit |
b513ef |
VALIGN="top"
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
HREF="c192.html"
|
|
Packit |
b513ef |
ACCESSKEY="U"
|
|
Packit |
b513ef |
>Up
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
WIDTH="33%"
|
|
Packit |
b513ef |
ALIGN="right"
|
|
Packit |
b513ef |
VALIGN="top"
|
|
Packit |
b513ef |
>Multi-threaded applications
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|
|
Packit |
b513ef |
>
|