Date: Thu, 12 Aug 2004 13:17:18 +0200 (CEST) Message-Id: <20040812.131718.74755885.oandrieu at nerim.net> To: seguso.forever at tin.it Cc: lablgtk at kaba.or.jp Subject: Re: (errata corrige) Screen for GtkWindow not set --- Warning: this expression should have type unit. From: Olivier Andrieu In-Reply-To: <200408091552.53159.seguso.forever at tin.it> References: <200408091552.53159.seguso.forever at tin.it> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, Maurizio Colucci [Mon, 9 Aug 2004]: > [in my previous message I forgot to say what the warnings are] > > Hello, > > I am trying to write an adventure game with lablgtk2 and lablgl. I > have installed debian sid which seemed to have a good support for > ocaml. Unfortunately I am getting warnings and runtime errors when > compiling hello world. > > This is the program I am trying to compile (hello.ml): > > > open GMain > > let window = GWindow.window ~border_width: 10 () > > let button = GButton.button ~label:"Hello World" ~packing: window#add () > > let main () = > window#event#connect#delete > ~callback:(fun _ -> prerr_endline "Delete event occured"; true); > window#connect#destroy ~callback:Main.quit; > button#connect#clicked ~callback:(fun () -> prerr_endline "Hello World"); > button#connect#clicked ~callback:window#destroy; > window#show (); > Main.main () > > let _ = Printexc.print main () > > > This is the Makefile I am using (written by me after reading the ocaml > manual): > > > all: hello.ml > ocamlc -I /usr/lib/ocaml/3.08/lablgl -I /usr/lib/ocaml/3.08/lablgtk2 > lablgtk.cma lablgl.cma lablgtkgl.cma hello.ml > > > I am getting these warnings: > > ocamlc -I /usr/lib/ocaml/3.08/lablgl -I /usr/lib/ocaml/3.08/lablgtk2 > lablgtk.cma lablgl.cma adv.ml > File "adv.ml", line 36, characters 2-52: > Warning: this expression should have type unit. > File "adv.ml", line 37, characters 2-42: > Warning: this expression should have type unit. > File "adv.ml", line 39, characters 2-40: > Warning: this expression should have type unit. > File "adv.ml", line 40, characters 2-49: > Warning: this expression should have type unit. that's because connecting signals returns a GtkSignal.id (it can be used to deconnect a signal). In your program you are discarding this value so ocaml emits a warning. Either compile your code with -w s or write it like this: let _ = window#connect#destroy ~callback:Main.quit in let _ = button#connect#clicked ... > > I don't understand the warnings. however, the program compiles > despite the warnings, but at runtime I am getting these errors: [snip] you did not init GTK+. See the README: ,----[ README ] | lablgtktop contains an extra module GtkInit, whose only contents is: | let locale = GtkMain.Main.init () | You must either add this line, or add this module to your link, | before calling any Gtk function. | ocamlc -I +lablgtk2 -w s lablgtk.cma gtkInit.cmo ???.ml -o ??? `---- -- Olivier