Frage

I am trying to compile a very small vignette to see how lablgtk2 works.

(* file: base.ml *)
let main () =
  let window = GWindow.window () in
  window#show ();
  GMain.Main.main ()

let _ = main ()

I have it properly installed via the wodi32 package manager and checked the pgk-lib folder to see that there are gMain.cmx/cmi and gWindow.cmx/cmi files (as well as the respective .ml and .mli files). However, when I run the following compile command:

$ ocamlc -I +lablgtk2 -o base lablgtk.cma gtkInit.cmo base.ml

I get the following error:

File "base.ml", line 4, characters 15-29:
Error: Unbound module GWindow

What's not correct? Why can it not find the GMain and GWindow modules? Is there an alternative command line compile directive I can use that will yield an executable (i.e. Windows/Linux style)? For example, is there a way to directly link the GMain and GWindow modules so the compiler understands that they're not unbound?

Weirdly enough, when I run the following command, things seem to work, but only yield an object file (i.e. base.o, as well as base.cmx, base.cmi):

$ ocamlfind opt -package lablgtk2 -linkpkg base.ml

How do I turn that object into an executable?

War es hilfreich?

Lösung

Always use ocamlfind as a wrapper for ocaml(c|opt), if you use libraries installed via ocamlfind (nearly all libraries provide ocamlfind support nowadays). Only ocamlfind can parse the 'META'-files of these libraries. And ocamlfind can install libraries to different locations (depending on your findlib.conf and certain environmental varibles), plain ocaml possibly won't find them with the '+lib'-notation.

The following should work:

ocamlfind ocamlopt -package lablgtk2.auto-init -linkpkg base.ml -o myprog.exe
ocamlfind ocamlc -package lablgtk2.auto-init -linkpkg base.ml -o myprog_byte.exe

'.auto-init' will add gtkInit for you.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top