Introduction into OcamlNet
 Component "netstring"
 Component "cgi"
General hints
   
General hints

Compiling programs that use OcamlNet

Thanks to the findlib package manager it is quite simple to compile programs that use OcamlNet components. For example, to byte-compile sample.ml that uses the netstring component, one has to execute the following command:

ocamlfind ocamlc -package netstring -c sample.ml

For the final link step, the command looks like this one:

ocamlfind ocamlc -package netstring -linkpkg -o sample sample.cmo

You can get more information about findlib here, and in the quickstart guide.

How to reduce the size of executables

By default, the Netstring component adds a large number of conversion tables to programs, no matter whether they are used or not. This increases the size of the programs by approximately 150 KB. Instead of adding all conversion tables, it is possible to select subsets as follows:

  • If only conversion between the ISO-8859 character sets, and UTF-8 and UTF-16 is needed, the link predicate netstring_only_iso will limit the number of linked tables to this subset. Add the predicate as follows to the link command:

    ocamlfind ocamlc -package netstring -predicates netstring_only_iso \
       -linkpkg -o sample sample.cmo
    

    The effect is that the module containing the tables for the Windows, IBM, Adobe, and Macintosh encodings is omitted.

  • If only conversion between ISO-8859-1, UTF-8, and UTF-16 is needed, the link predicate netstring_minimum will leave out all conversion tables. (These character sets can be converted to each other without the help of such tables.)