Johannes Kolb
Johannes Kolb

Reputation: 40

OCaml error: Unbound module Event

I try to build a short ocaml event example. But when I compile, the error in the title appears.

The question of: unbound module Event error when compiling Ocaml game was not helpful for me.

The system is Kubuntu 14.04 and I installed ocaml over aptitude, so installed packages are:

camlp4, ledit, libfindlib-ocaml, libfindlib-ocaml-dev, liboasis-ocaml, liboasis-ocaml-dev, libodn-ocaml, libodn-ocaml-dev, libtype-conv-camlp4-dev, oasis, ocaml, ocaml-base, ocaml-base-nox, ocaml-compiler-libs, ocaml-doc, ocaml-findlib, ocaml-interp, ocaml-native-compilers, ocaml-nox

The OCaml compiler is version 4.01.0

Here is my short test program.

open Thread;;
open Event;;

let chan = Event.new_channel();;

let a () =
    Printf.printf "A waiting...\n";;
    let sigRX = Event.receive chan  in
        Printf.printf "A received over channel\n";
        let v = Event.sync sigRx  in
            Printf.printf "A running\n";
    Printf.printf "A done!\n";;

let b () = 
    Thread.delay 0.8
    Printf.printf "B sending...\n";;
    let sigTX = Event.send "wake up"  in
        Event.sync sigTX;
        Printf.printf "B done!\n";;


let t_a = Thread.create a ();;
let t_b = Thread.create b ();;

I tried to compile this single file (test.ml) with:

ocamlc -thread unix.cma threads.cma test.ml

The response is:

File "test.ml", line 2, characters 0-10:
Error: Unbound module Event

I googled, found some "thread-using-tips" like: http://caml.inria.fr/pub/docs/manual-ocaml/libthreads.html#c%3Athreads

In /usr/lib/ocaml is an threads folder and an thread.mli. Inside the threads folder there are this files:

-rw-r--r-- 1 root root   487 Jan  2  2014 condition.cmi
-rw-r--r-- 1 root root   487 Jan  2  2014 condition.cmx
-rw-r--r-- 1 root root  1203 Jan  2  2014 event.cmi
-rw-r--r-- 1 root root  1867 Jan  2  2014 event.cmx
-rw-r--r-- 1 root root   421 Jan  2  2014 mutex.cmi
-rw-r--r-- 1 root root   407 Jan  2  2014 mutex.cmx
-rw-r--r-- 1 root root  1859 Jan  2  2014 thread.cmi
-rw-r--r-- 1 root root  1308 Jan  2  2014 thread.cmx
-rw-r--r-- 1 root root 62778 Jan  2  2014 threads.a
-rw-r--r-- 1 root root 47047 Jan  2  2014 threads.cma
-rw-r--r-- 1 root root  1258 Jan  2  2014 threads.cmxa
-rw-r--r-- 1 root root  4145 Jan  2  2014 threadUnix.cmi
-rw-r--r-- 1 root root  1515 Jan  2  2014 threadUnix.cmx

What am I missing? I assume, that the Event is packed in Thread Module?

Upvotes: 1

Views: 2013

Answers (1)

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66803

This command line works for me to get past the unbound module problem.

$ ocamlc -I +threads -c test.ml

There are errors in your code, but I imagine you'll know how to fix them.

This full command line will probably work, but I can't be sure because of the errors:

$ ocamlc -thread -I +threads unix.cma threads.cma test.ml

(There are some higher-level tools for building OCaml programs that you might want to learn about at some point.)

Upvotes: 0

Related Questions