
wellingtonXD
(usa Ubuntu)
Enviado em 21/08/2011 - 01:34h
Pessoal, eu compilei um programa que eu vi em tutorial, mas na hora de executar ele retorna falha de segmentação, eis o código:
#include <stdio.h>
#include <gtk/gtk.h>
static GtkWidget *entry;
static gboolean kill_window(GtkWidget *widget, GdkEvent *event, gpointer data)
{
gtk_main_quit();
return FALSE;
}
static void button_press(GtkWidget *widget, gpointer data)
{
const char *text = gtk_entry_get_text(GTK_ENTRY(entry));
printf("%s\n",text);
}
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *hbox;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
button = gtk_button_new_with_label("print");
entry = gtk_entry_new;
hbox = gtk_hbox_new(FALSE, 2);
gtk_window_set_title(GTK_WINDOW(window),"Aplicação GTK");
g_signal_connect(window, "delete_event",G_CALLBACK(kill_window), NULL);
g_signal_connect(button,"clicked", G_CALLBACK(button_press), NULL);
gtk_box_pack_start(GTK_BOX(hbox),entry, TRUE, TRUE, 2);
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 2);
gtk_container_add(GTK_CONTAINER(window), hbox);
gtk_widget_show(button);
gtk_widget_show(hbox);
gtk_widget_show(window);
gtk_main();
return 0;
}
eu compilei assim:
gcc -std=c99 -O2 window.c `pkg-config --libs --cflags gtk+-2.0`
mas na hora que eu executo ele retorna falha de segmentação, alguém sabe dizer por que??