Re: Beginner difficulty with first tutorial program



Jonathan Hayward wrote:

I've installed 2.4.9 under FC4, and when something else didn't work, tried to compile and run the tutorial's sample program. I created test.c:

#include <gtk/gtk.h>

int main(int argc, char *argv[])
    {
    GtkWidget *window;
    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_main();
    return 0;
    }

Then I compiled it with a Makefile:

CC = gcc

CFLAGS = -c -g -O2 -Wall `pkg-config --cflags gtk+-2.0`

LIBS = -lm `pkg-config --libs gtk+-2.0`

test: test.o
    $(CC) test.o $(LIBS) -o test

test.o: test.c
    $(CC) $(CFLAGS) test.c

According to the tutorial, this should get a blank 200x200 window. When I ran it, however, it seemed to lag; a backtrace from gdb indicated that I had [without seeing a window] got past the code that should start the window, and into the event loop:

Program received signal SIGINT, Interrupt.
0x005cb402 in __kernel_vsyscall ()
(gdb) backtrace
#0  0x005cb402 in __kernel_vsyscall ()
#1  0x00b77cb9 in poll () from /lib/libc.so.6
#2  0x0026a248 in g_main_context_check () from /usr/lib/libglib-2.0.so.0
#3  0x0026a6e3 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#4  0x0070c1b5 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#5  0x080485aa in main (argc=1, argv=0xbfc52224) at test.c:9

What should I be doing differently?


you should show the window

like that:

#include <gtk/gtk.h>

int main(int argc, char *argv[])
   {
   GtkWidget *window;
   gtk_init(&argc, &argv);
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_widget_show (window);
   gtk_main();
   return 0;
}

cu jochen









[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]