我正在研究Debian Stable,并已从Debian存储库安装了ocaml和opam。我正在尝试遵循here中的代码:
#directory "+labltk"
#load "labltk.cma"
let () =
let top = Tk.openTk() in
Wm.title_set top "Tk-OCaml Example";
let label = Label.create ~text:"There have been no clicks yet" top in
let b =
Button.create
~text:"click me"
~command:(fun () -> Tk.closeTk (); exit 0)
top
in
Tk.pack [Tk.coe label; Tk.coe b];
Tk.mainLoop ();
;;
但是,我遇到以下错误:
$ ocaml simplewin.ml
Cannot find file labltk.cma.
File "simplewin.ml", line 5, characters 12-21:
Error: Unbound module Tk
我已安装labltk
模块:
$ opam list labltk
# Available packages for system:
labltk 8.06.0 OCaml interface to Tcl/Tk, including OCaml library explorer OCamlBrowser
问题出在哪里,如何解决?感谢您的帮助。
答案 0 :(得分:0)
自OCaml 4.02起,Labltk不再随编译器一起分发。因此,
#directory "+labltk";;
#load "labltk.cma";;
不是正确的命令:您应该使用
#require "labltk";;
编辑:以下代码对我有用:
#require "labltk";;
let () =
let top = Tk.openTk() in
Wm.title_set top "Tk-OCaml Example";
let label =
Label.create ~text:"There have been no clicks yet" top in
let b =
Button.create
~text:"click me"
~command:(fun () -> Tk.closeTk (); exit 0)
top
in
Tk.pack [Tk.coe label; Tk.coe b];
Tk.mainLoop ();
;;