Ocaml 执行gtk应用程序时出现SEGFULT

Ocaml 执行gtk应用程序时出现SEGFULT,ocaml,Ocaml,我跟在后面 但当我使用第一个代码和命令时: ocamlfind ocamlc -g -package lablgtk2 -linkpkg simple.ml -o simple 我收到警告: File "simple.ml", line 8, characters 2-44: Warning 10: this expression should have type unit. File "simple.ml", line 18, characters 2-54: Warning 10: thi

我跟在后面 但当我使用第一个代码和命令时:

ocamlfind ocamlc -g -package lablgtk2 -linkpkg simple.ml -o simple
我收到警告:

File "simple.ml", line 8, characters 2-44:
Warning 10: this expression should have type unit.
File "simple.ml", line 18, characters 2-54:
Warning 10: this expression should have type unit.
File "simple.ml", line 23, characters 2-69:
Warning 10: this expression should have type unit.
当我命令:
/simple
我得到了:

(process:7015): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(process:7015): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(process:7015): Gtk-CRITICAL **: IA__gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7015): GLib-GObject-CRITICAL **: g_object_get: assertion 'G_IS_OBJECT (object)' failed

(process:7015): Gtk-CRITICAL **: IA__gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7015): GLib-GObject-CRITICAL **: g_object_get: assertion 'G_IS_OBJECT (object)' failed

(process:7015): GLib-CRITICAL **: g_hash_table_lookup: assertion 'hash_table != NULL' failed

(process:7015): GLib-CRITICAL **: g_hash_table_insert_internal: assertion 'hash_table != NULL' failed

(process:7015): GLib-CRITICAL **: g_hash_table_lookup: assertion 'hash_table != NULL' failed

(process:7015): GLib-CRITICAL **: g_hash_table_insert_internal: assertion 'hash_table != NULL' failed

(process:7015): GLib-CRITICAL **: g_hash_table_lookup: assertion 'hash_table != NULL' failed

(process:7015): GLib-CRITICAL **: g_hash_table_lookup: assertion 'hash_table != NULL' failed

(process:7015): GLib-CRITICAL **: g_hash_table_lookup: assertion 'hash_table != NULL' failed

(process:7015): GLib-CRITICAL **: g_hash_table_insert_internal: assertion 'hash_table != NULL' failed

(process:7015): GLib-CRITICAL **: g_hash_table_lookup: assertion 'hash_table != NULL' failed
segfault.

我错在哪里?毕竟,这是来自官方网站的示例。

看起来教程的代码没有调用
lablgtk
的初始值设定项(它反过来负责初始化
gtk
的内部)。根据需要,只需将编译命令行更改为

ocamlfind ocamlc -g -package lablgtk2.auto-init -linkpkg simple.ml -o simple
或者,您可以直接在
simple.ml
的开头添加初始化代码:

let _ = GtkMain.Main.init ()
它可能来自“officia”网站,但该网站已收集了有关常用软件包的教程,并允许提供帮助。您使用的软件版本是什么?(GTK和OCaml)