Using LibGlade support in LablGtk2
I played with the following glade example files from LablGtk2:
- gladecalc.ml
- project2.glade
You can find them from the liblablgtk2-ocaml-dev package if you are using Debian Gnu/Linux Sid.
To run the gladecalc.ml you should do the following first:
1 | lablgladecc2 -embed project2.glade > project2.ml |
then you can run gladecalc.ml:
1 | lablgtk2 -thread gladecalc.ml |
This might not be very useful if you want to deploy your own LablGtk2 applications and the clients don't have OCaml toplevel installed: lablgtk2 is just a shell script wrapped around OCaml toplevel after all.
In our case, to compile gladecalc.ml into a native executable, we should first change the code a little bit. The #use directive in line 6 of gladecalc.ml works only for OCaml toplevel, so comment it out and add a new line:
1 | (* #use "project2.ml";; *) |
then use ocamlopt to compile:
1 | ocamlopt -I +lablgtk2 lablgtk.cmxa lablglade.cmxa gtkInit.cmx project2.ml gladecalc.ml -o gladecalc |
this produces a single executable "gladecalc" without OCaml dependencies.