caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Prevost <j.prevost@gmail.com>
To: "Juancarlo Añez" <juanca@suigeneris.org>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] OCAML Newby Question: unbound module?
Date: Fri, 11 Feb 2005 09:45:05 -0500	[thread overview]
Message-ID: <d849ad2a05021106458ba5a06@mail.gmail.com> (raw)
In-Reply-To: <200502101624.j1AGO3qP019814@concorde.inria.fr>

On Thu, 10 Feb 2005 12:23:57 -0400, Juancarlo Añez
<juanca@suigeneris.org> wrote:
> Below is the first few lines of code I wrote. Whey I try to run it with
> ocaml, I get:
> 
> "File "pattensets.ml", line 1, characters 0-11:
> Unbound module Dumper"
> 
> Dumper.mil and dumper.ml are in the same directory.
> 
> What am I doing wrong?

First, the filenames should be dumper.mli and dumper.ml  (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 dumper.ml
# produce the .cmo file from the .ml file
ocamlc -c program.ml
# produce the executable from the .cmo files
ocamlc -o program dumper.cmo program.cmo

Or in short:
ocamlc -o program dumper.mli dumper.ml program.ml

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
available.)

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

John.


      reply	other threads:[~2005-02-11 14:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-07  8:41 Socket and Threads on windows Julien Boulnois
2005-02-07 10:33 ` [Caml-list] " Olivier Pérès
2005-02-07 11:05   ` Julien Boulnois
2005-02-10 16:23     ` OCAML Newby Question: unbound module? Juancarlo Añez
2005-02-11 14:45       ` John Prevost [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d849ad2a05021106458ba5a06@mail.gmail.com \
    --to=j.prevost@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=juanca@suigeneris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).