Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Socket and Threads on windows
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Prevost <j.prevost@g...>
Subject: Re: [Caml-list] OCAML Newby Question: unbound module?
On Thu, 10 Feb 2005 12:23:57 -0400, Juancarlo Añez
<> wrote:
> Below is the first few lines of code I wrote. Whey I try to run it with
> ocaml, I get:
> "File "", line 1, characters 0-11:
> Unbound module Dumper"
> and are in the same directory.
> What am I doing wrong?

First, the filenames should be dumper.mli and  (I expect
these are correct, but just checking.)  Second, unlike with javac, you
must tell ocamlc which source files to compile and/or link, and in
what order.  In this case:

# produce the .cmi file from the .mli file
ocamlc -c dumper.mli
# produce the .cmo file from the .ml file
ocamlc -c
# produce the .cmo file from the .ml file
ocamlc -c
# produce the executable from the .cmo files
ocamlc -o program dumper.cmo program.cmo

Or in short:
ocamlc -o program dumper.mli

Note that ocamlopt is pretty much the same, but the extensions of .cmo
change to .cmx.  The reason that you need to specify the order in
which files are listed for linking is that this determines which
modules are in scope at any point, and also determines an order for
the initialization of each module.

Finally, if you are trying to run in the ocaml toplevel, you want to
do the steps above to produce the .cmo file for dumper, then:

#load "dumper.cmo";;

in the toplevel will cause the compiled code for dumper to be loaded
into memory.  (The compiled interface, dumper.cmi, will be found and
loaded automatically when you first refer to the Dumper module, but
until you load the .cmo file, the values from the module will not be

You might want to take a look at the ocaml beginner's list:
or at chapter 8 of the manual (Batch Compilation (ocamlc)) if you have
more problems like this.