My first GTK program…

I went through the tutorial websites and wanted to write a code in GTK for the first time…

I was able to get good hint of the structure of the programs, since the programing structure is quite similar to the one in Java Swings… ( I was quite good in Java Swings) except that only the syntaxes and a very few things are different.

My first program in GTK is :

#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;
}
 
Happily saved my program as firstgtk.c   🙂
 
I learnt from http://www.gtk.org/tutorial1.2/gtk_tut-2.html#ss2.1 how to compile in simple syntax...
gcc -o hello firstgtk.c `gtk-config --cflags --libs` 
 
Sadly... The machine started scolding me as...
 
Must specify package names on the command line
base.c:1:21: error: gtk/gtk.h: No such file or directory
base.c: In function ‘main’:
base.c:6: error: ‘GtkWidget’ undeclared (first use in this function)
base.c:6: error: (Each undeclared identifier is reported only once
base.c:6: error: for each function it appears in.)
base.c:6: error: ‘window’ undeclared (first use in this function)
base.c:9: error: ‘GTK_WINDOW_TOPLEVEL’ undeclared (first use in this function)
 
Honestly I don't know the issue... Again started searching for a better syntax for compiling the gtk program...

 This time, http://library.gnome.org/devel/gtk-tutorial/2.17/c39.html gave me a better syntax as:
gcc firstgtk.c -o base `pkg-config --cflags --libs gtk+-2.0`

 
Cool... It worked well !!!

And now I just tried executing it as : 
./base

I was happy to see a small window🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s