Reputation: 11
I' following https://ocaml.org/learn/tutorials/introduction_to_gtk.html But when I used first code and command:
ocamlfind ocamlc -g -package lablgtk2 -linkpkg simple.ml -o simple
I got warnings:
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.
What more when I command: ./simple
I got:
(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.
Where I am wrong ? After all, it is example from official site.
Upvotes: 1
Views: 758
Reputation: 10158
It looks like the code of the tutorial does not call lablgtk
's initializer (which in turn takes care of initializing gtk
's internals). According to http://lablgtk.forge.ocamlcore.org/README.html you can simply change your compilation command line to
ocamlfind ocamlc -g -package lablgtk2.auto-init -linkpkg simple.ml -o simple
Alternatively, you can add the initialization code at the beginning of simple.ml
directly:
let _ = GtkMain.Main.init ()
Upvotes: 3