Ocaml无法找到Labltk

问题描述 投票:0回答:1

我正在使用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

问题在哪里,如何解决?谢谢你的帮助。

window ocaml
1个回答
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 ();
;;
© www.soinside.com 2019 - 2024. All rights reserved.