函数应用于lablgtk中太多的参数 [英] Function applied to too many arguments in lablgtk

查看:129
本文介绍了函数应用于lablgtk中太多的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来理解为什么下面的代码不能编译。我试图将GSourceView2放在lablgtk的垂直框中。我修改了 Ocaml文章中的代码。

 打开GMain 
打开GdkKeysyms

让locale = GtkMain.Main.init()

let
let vbox = GPack.vbox〜包装:
let title window:GWindow.window〜width:320〜height:240
〜title:Simple lablgtk program窗口#add()在
窗口中#connect#destroy〜callback:Main.quit;

(* Sourceview *)
let _ = new GSourceView2.source_view〜height:240〜width:320〜packing:vbox#add()in

window #显示 ();
Main.main()

let()= main()



 错误:此函数的类型为
GtkSourceView2_types.source_view Gtk .obj - > GSourceView2.source_view
它适用于太多的参数;也许你忘了';'。

但是,我可以创建一个GButton并将其pack参数放在vbox中。 GButton.button GSourceView2.source_view 看起来非常相似(很多可选参数后跟一个单元),所以我不太确定我错过了什么。任何对我所缺少的帮助都会非常有帮助,因为我对这种语言还很陌生。

既然你是这种语言的新手,我也会告诉你我是如何解决这个问题的,以便你对环境有一个感觉......不幸的是,这有时会很痛苦。

所以你得到的错误意味着缺少 cma cmxa (我不确定你是否使用了ocamlopt或ocamlc)



让我们先来看看源代码...我们可以在



〜/ .opam / archives / 或者仅由 opam source lablgtk 。我们进去看看一个META文件,这是用于 ocamlfind 的。

cat META 之后,我们看到这个相关部分一直在底部。

  packagesourceview2(
exists_if =lablgtksourceview2.cma,lablgtksourceview2.cmxa,lablgtksourceview2.cmxs
description =Bindings for gtksourceview2
requires =lablgtk2
archive(byte)=lablgtksourceview2.cma
archive(native)=lablgtksourceview2.cmxa

没问题,所以这意味着我们应该期望lablgtksourceview2.cma或.cmxa存在。我们可以这样做:

$ $ p coded> ocamlfind query lablgtk`

,然后我们可以执行 locate lablgtksource2.cma find。 -name lablgtksourceview2.cma 。在我的平台上,OS X都不存在。在lablgtk网站和一般的搜索引擎上进行了一些调查之后,这是因为相关的gtk代码本身不在我的机器上。



对于OS X上的OCaml用户,您需要

  1) opam uninstall lablgtk 
(*请确保您的路径设置正确,用于PKG_CONFIG_PATH = / opt / X11 / lib / pkgconfig *)
2)brew install gtksourceview libxml2
3)opam install lablgtk lablgtk-extras

最后一步可能会导致错误。它最可能是一个pkg-config路径问题,
这是我的 PKG_CONFIG_PATH = /opt/X11/lib/pkgconfig/:/usr/local/Cellar/libxml2/2.9.2/lib/对于OCaml人来说,我猜基于Debian的机器,这应该包括Ubuntu,
,但我不确定是否需要使用pkgconfig /

这是正确的包名称。

  1)opam uninstall lablgtk 
2)apt-get install liblablgtksourceview2-ocaml-dev
(*不知道什么是正确的pkgconfig东西在Linux上,但不应该问题我想*)
3)opam install lablgtk lablgtk-extras

您可以在此之后再次检查 .cma dance,并检查

  pwd 
/Users/Edgar/.opam/4.02.1/lib/lablgtk2
〜/ .o / 4 / l / lablgtk2❯❯❯ ls * .cma
lablglade.cma lablgtksourceview2.cma
lablgtk.cma lablrsvg.cma



,相关的 cma 存在。
我们也可以仔细检查:

  ocamlfind list | grep gtk 
lablgtk2(版本:2.18.0)
lablgtk2-extras(版本:1.5)
lablgtk2-extras.configwin(版本:1.5)
lablgtk2.auto-init (版本:n / a)
lablgtk2.glade $ b

并且有相关的包,sourceview2。



现在您的代码完全独立:

  #require lablgtk2.sourceview2
打开GMain
打开GdkKeysyms

让locale = GtkMain.Main.init()

let main()=
让窗口= GWindow.window〜宽度:320〜高度:240
〜title:$ SimpleBit $ gt;
let vbox = GPack.vbox〜packing:window#add()in
window#connect#destroy〜callback:Main.quit;

(* Sourceview *)
let _ = GSourceView2.source_view〜height:240〜width:320〜packing:vbox#add()in

window#显示 ();
Main.main()

let()= main()

我可以用 utop< the_file.ml>



成功运行它如果您喜欢使用ocamlc或ocamlopt然后删除以#require开头的行,因为这只是为了utop,然后执行:

 (*我刚刚命名它stackoverflow.ml,你也可以使用ocamlopt而不是ocamlc *)

ocamlfind ocamlc -package lablgtk2.sourceview2 -linkpkg stackoverflow.ml -o SanityCheck

然后 ./ SanityCheck 在OS X上适用于我。


I need some help understanding why the following code will not compile. I am attempting to place a GSourceView2 inside a vertical box in lablgtk. I've adapted the code from this Ocaml article

open GMain
open GdkKeysyms

let locale = GtkMain.Main.init ()

let main () =
  let window = GWindow.window ~width:320 ~height:240
                              ~title:"Simple lablgtk program" () in
  let vbox = GPack.vbox ~packing:window#add () in
  window#connect#destroy ~callback:Main.quit;

  (* Sourceview *)
  let _ = new GSourceView2.source_view ~height:240 ~width:320 ~packing:vbox#add () in

  window#show ();
  Main.main ()

let () = main ()

The error I get is a bit cryptic:

Error: This function has type
         GtkSourceView2_types.source_view Gtk.obj -> GSourceView2.source_view
       It is applied to too many arguments; maybe you forgot a `;'.

However, I can instead create a GButton and set its pack argument to place it inside the vbox. The signatures for both GButton.button and GSourceView2.source_view appear to be very similar (lots of optional args followed by a unit), so I'm not quite sure what I'm missing. Any help on what I'm missing would be very helpful, as I'm still fairly new to this language.

解决方案

Since you are new to this language, I will also give you the overview of how I solved this problem so that you get a feel for the environment...unfortunately this can painful at times.

So the error you got implied the lack of a cma or cmxa (I'm not sure if you used ocamlopt or ocamlc)

Let's start by going to the source...which is available to us in either

~/.opam/archives/ or just by opam source lablgtk. We go in and see a META file, this is for ocamlfind.

after cat META we see this relevant part all the way on the bottom.

package "sourceview2" (
  exists_if = "lablgtksourceview2.cma,lablgtksourceview2.cmxa,lablgtksourceview2.cmxs"
  description = "Bindings for gtksourceview2"
  requires = "lablgtk2"
  archive(byte) = "lablgtksourceview2.cma"
  archive(native) = "lablgtksourceview2.cmxa"
)

okay, so that means that we should expect a lablgtksourceview2.cma or .cmxa to exist. We can do

cd `ocamlfind query lablgtk`

and then we can do either locate lablgtksource2.cma or find . -name lablgtksourceview2.cma. On my platform, OS X, neither existed. After some sleuthing on the lablgtk site and general googling, this was because the relevant gtk code itself was not on my machine.

for OCaml people on OS X you need to

1) opam uninstall lablgtk
(* Make sure that your path is set up correctly for PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig *)
2) brew install gtksourceview libxml2
3) opam install lablgtk lablgtk-extras

The last step might crap out. Its most likely a pkg-config path issue, Here's mine for PKG_CONFIG_PATH = /opt/X11/lib/pkgconfig/:/usr/local/Cellar/libxml2/2.9.2/lib/pkgconfig/

for OCaml people on I guess Debian based machines, this should include Ubuntu, although I'm not sure if this is the correct package name for this.

1) opam uninstall lablgtk
2) apt-get install liblablgtksourceview2-ocaml-dev
(* Not sure what the correct pkgconfig stuff is on linux but shouldn't matter I imagine *)
3) opam install lablgtk lablgtk-extras

You can do the checking for the .cma dance again after this and check with

 pwd
/Users/Edgar/.opam/4.02.1/lib/lablgtk2
~/.o/4/l/lablgtk2 ❯❯❯ ls *.cma
lablglade.cma          lablgtksourceview2.cma
lablgtk.cma            lablrsvg.cma

Yay, the relevant cma exists. We can also double check with:

ocamlfind list | grep gtk
lablgtk2            (version: 2.18.0)
lablgtk2-extras     (version: 1.5)
lablgtk2-extras.configwin (version: 1.5)
lablgtk2.auto-init  (version: n/a)
lablgtk2.glade      (version: n/a)
lablgtk2.rsvg       (version: n/a)
lablgtk2.sourceview2 (version: n/a)

and there's the relevant package, sourceview2.

Now here's your code completely self contained:

#require "lablgtk2.sourceview2"
open GMain
open GdkKeysyms

let locale = GtkMain.Main.init ()

let main () =
  let window = GWindow.window ~width:320 ~height:240
                              ~title:"Simple lablgtk program" () in
  let vbox = GPack.vbox ~packing:window#add () in
  window#connect#destroy ~callback:Main.quit;

  (* Sourceview *)
  let _ = GSourceView2.source_view ~height:240 ~width:320 ~packing:vbox#add () in

  window#show ();
  Main.main ()

let () = main ()

and I can run it successfully with utop <the_file.ml>

If you prefer to use ocamlc or ocamlopt then remove the line that starts with #require since that's just for utop, then do:

(* I just named it stackoverflow.ml, you can also use ocamlopt instead of ocamlc *)

ocamlfind ocamlc -package lablgtk2.sourceview2 -linkpkg stackoverflow.ml -o SanityCheck

Then ./SanityCheck which worked for me on OS X.

这篇关于函数应用于lablgtk中太多的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆