| up |
See the file INSTALL for instructions how to build and install findlib.
For a number of platforms, O'Caml can load bytecode-compiled libraries dynamically. For these platforms, findlib is very simple to use as explained in the following. For other platforms, see the paragraph below about "custom toploops".
After the toploop has been started, it is possible to load the special findlib support:[1]
$ ocaml
Objective Caml version 3.07
# #use "topfind";;
Findlib has been successfully loaded. Additional directives:
#require "package";; to load a package
#list;; to list the available packages
#camlp4o;; to load camlp4 (standard syntax)
#camlp4r;; to load camlp4 (revised syntax)
#predicates "p,q,...";; to set these predicates
Topfind.reset();; to force that packages will be reloaded
#thread;; to enable threads
- : unit = ()
You can now list the available packages:
# #list;; bigarray (version: [distributed with Ocaml]) camlp4 (version: Camlp4 version 3.03 ALPHA) dbm (version: [distributed with Ocaml]) dynlink (version: [distributed with Ocaml]) findlib (version: 0.6) graphics (version: [distributed with Ocaml]) labltk (version: [distributed with Ocaml]) netstring (version: 0.10) num (version: [distributed with Ocaml]) stdlib (version: [distributed with Ocaml]) str (version: [distributed with Ocaml]) threads (version: [distributed with Ocaml]) unix (version: [distributed with Ocaml]) xstrp4 (version: 1.1)and load packages by simply typing:
# #require "netstring";; Loading /opt/ocaml/lib/unix.cma Loading /opt/ocaml/lib/str.cma Loading /opt/ocaml/site-lib/netstring/netstring.cma Loading /opt/ocaml/site-lib/netstring/netstring_top.cmoFindlib takes care to load packages that are required by loaded packages first. For example, "netstring" uses "unix" and "str" internally, but you do not need to load them because findlib does it for you. In this example you can also see that findlib loads netstring_top.cmo containing printers for the toploop.
You can also enable the Camlp4 parsers by simply typing
# #camlp4o;;
Loading /opt/ocaml-3.03a/lib/camlp4/camlp4o.cma
Camlp4 Parsing version 3.03 ALPHA
for the standard syntax or
# #camlp4r;;
Loading /opt/ocaml-3.03a/lib/camlp4/camlp4r.cma
Camlp4 Parsing version 3.03 ALPHA
for the revised syntax. (But you cannot switch between the syntaxes.)
For some platforms, O'Caml does not implement loading external libraries (e.g. Cygwin). One has to create a so-called custom toploop that statically links with these libraries. Example:
$ ocamlfind ocamlmktop -o mytop -package findlib,unix -linkpkg
$ ./mytop
Objective Caml version 3.07
# #use "topfind";;
Findlib has been successfully loaded. Additional directives:
#require "package";; to load a package
#list;; to list the available packages
#camlp4o;; to load camlp4 (standard syntax)
#camlp4r;; to load camlp4 (revised syntax)
#predicates "p,q,...";; to set these predicates
Topfind.reset();; to force that packages will be reloaded
#thread;; to enable threads
- : unit = ()
Now "#require" works for all libraries es foT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
>| The findlib User's Guide | ||
|---|---|---|
| Prev | Chapter 7. FAQs | |
A conflict means that a certain combination of packages and package features will not work. A number of conflict conditions can be expressed:
To state that a package will not work if a certain predicate is set, use the error variable. For example, when package p does not work for multi-threaded programs:
error(mt) = "Package p is incompatible with multi-threaded programs"This works for other standard predicates, too.
To state that a package will not work together with another package, it is possible to make error dependent on package predicates. For example, when package p does not work together with q:
error(pkg_q) = "Package p is incompatible with package q"This also works with subpackages (e.g. pkg_q.q_sub).
Note that such error conditions should only be added if there is absolutely no chance to get the combination of packages and features running. For example, in the case of multi-threaded programs it is often possible to add wrappers around unsafe libraries to fix the incompatibility.
It is not possible to express incompatibilities between package versions. Such incompatibilities should be detected when software is installed, not when it is used.