LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GTK programming (https://www.linuxquestions.org/questions/programming-9/gtk-programming-341896/)

exvor 07-10-2005 01:48 PM

GTK programming
 
Ok after checking out ncurses and xlib im trying to figure out what im doing
wrong here. The tutorial im reading wants to create a basic program that
creates a window.


here is the code.

Code:

#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);
}

im compiling with gcc -o test main.c 'gtk-config --cflags --libs'


and i have gtk-1.2 and 2.0 installed

i get the compiler error GtkWidget undefined and GTK_WINDOW_TOPLEVEL undefined.


shouldent these be defined in the header file ???

acid_kewpie 07-10-2005 02:17 PM

hmm, yeah it should be included... does "gtk-config --libs --cflags" present the right details though? Maybe that's a gtk-1.4 thing?

But really... can i just suggest that you don't bother? instead use gtk2 instead.. why bother learning a deprecated library that is no longer supported?

exvor 07-10-2005 02:23 PM

Hmm i thought this was gtk 2.0 programming model.

know of any tutorials that have the updated 2.0 stuff ??

C language of course not C++

acid_kewpie 07-10-2005 04:09 PM

gtk.org for everything really... i forget the code differences between the two, so maybe that IS gtk2 code, BUT you are definitely linking on gtk1 libraries. gtk1 uses the gtk-config gubbins, whilst gtk2 uses the mroe complete pkg-config framework for getting libs and cflag values.

elyk 07-10-2005 11:34 PM

Try replacing your compile command:
gcc -o test main.c 'gtk-config --cflags --libs'

with this one:
gcc -o test main.c `pkg-config --cflags --libs gtk+-2.0`

Notice the different quote marks around the last half of the command, that may be part of your problem.

vharishankar 07-10-2005 11:36 PM

I would suggest you use an IDE for developing large GUI applications.

Much easier and saves quite a bit of trouble compiling.

Anjuta is a good IDE for GTK and Gnome development while KDevelop is also a very good general purpose IDE.

exvor 07-11-2005 12:25 AM

Yea that was the issue it was the ` ohh on the gtk+-2.0 page the latest one is not there its supposed to be but its not. I installed that and now am trying to solve another issue with compiling a simple hello world program keeps giving me a parse error but i see no error with the syntax. ??

here is the line gcc is not likeing
Code:

static gboolean delete_event (GtkWidget *widget, GtkEvent *event  , gpointer data)
I get a gcc error of parse error before GtkEvent;


It looks fine to me for a function im not familliar with gboolean tho is that the issue?

acid_kewpie 07-11-2005 01:03 AM

I think you shoulda copied and pasted it instead of retyping..! it's GdkEvent, not a GtkEvent.

exvor 07-11-2005 01:14 AM

Ok somehow by removeing my /* */ to track the issue im no longer getting a syntax error but another has occured here let me just post the whole code.

Code:

#include <gtk/gtk.h>
static void hello(GtkWidget *widget, gpointer data)
{
        g_print("Hello World\n");

}
static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
  g_print("Delete Event occured");


        return TRUE;
}
 
 static void destroy (GtkWidget *widget,gpointer data)
{
gtk_main_quit();
}

int main(int argc, char *argv[])

{
        GtkWidget *window;
        GtkWidget *button;       

gtk_init (&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);


g_signal_connect (G_OBJECT (window), "delete_event",G_CALLBACK (delete_event),NULL);


g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL);

gtk_container_set_border_width (GTK_CONTAINER (window), 10);

button = gtk_button_new_with_label ("Hello World");

g_signel_connect (G_OBJECT (button), "clicked", G_CALLBACK (hello), NULL);

g_signel_connect_swapped ( G_OBJECT (button), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT
(window));

gtk_container_add (GTK_CONTAINER (window), button);
 
gtk_widget_show (button);

gtk_widget_show (window);

gtk_main();

return 0;

}


im double checking my code to see if I copied something wrong. but if you find it here before I do then cool.

ohh here is what im copying http://www.gtk.org/tutorial/ch-getti...SEC-HELLOWORLD

exvor 07-11-2005 01:25 AM

Never mind i found it.

lol helps if i spell signal correctly.

exvor 07-11-2005 03:59 AM

Cool well Im experimenting more and more with gtk+-2.0 im starting to see why programmers like this interface for creating gui apps. Its much eazier to figure out then xlib or ncurses. Maybe its just me tho , but its something at least i can understand why this is here and why thats there in the programming code.


All times are GMT -5. The time now is 12:53 AM.