tags:

views:

108

answers:

2

Hi. I wrote app in ocaml. It consist of several modules: Util (util.ml) Work1 (work1.ml) -- open Util Work2 (work2.ml) -- open Util, too Main (main.ml) -- open all of them.

When i compile its, using ocamlc, compilation failed on module Work2, and i get error message about unbound value from Util. Separate compilation doesn't work, too. What i do wrong?

ocamlc -o app.out -vmthread -pp camlp4o.opt unix.cma threads.cma camlp4of.cma util.ml work1.ml work2.ml main.ml

Thanks!

+1  A: 

The order of files on the commandline is significant in OCaml. You must put the files in dependency order. This is probably the problem you are having. Try changing the order of the files until it works...

Pascal Cuoq
A: 

If you have the modules like the following :

module Util
    ...
end;;

module Work2
     open Util
     ...
end;;

module Main
    open Util;;
    open Work2;;
    ...
end;;

Module Work1
    open Work2;;
    ...
end;;

then the order must be in the way that when each module calls open it find the opened module already compiler, in the example abover the order would be

Util -> Work2 -> Work1 -> Main

Notice that OCaml doesn't support cyclic redundency for modules, means you can't have

module Work1
       open Work2;;
end;;

module Work2
       open Work1;;
end;;

if your app is a little complicated with a lot of modules, you can use Ocamldep http://caml.inria.fr/pub/docs/manual-ocaml/manual027.html and it will figure out the graph dependency for you.

martani_net