LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-10-2005, 01:48 PM   #1
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,483

Rep: Reputation: 66
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 ???
 
Old 07-10-2005, 02:17 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,373

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
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?
 
Old 07-10-2005, 02:23 PM   #3
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,483

Original Poster
Rep: Reputation: 66
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++
 
Old 07-10-2005, 04:09 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,373

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
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.
 
Old 07-10-2005, 11:34 PM   #5
elyk
Member
 
Registered: Jun 2004
Distribution: Slackware
Posts: 162

Rep: Reputation: 23
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.
 
Old 07-10-2005, 11:36 PM   #6
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,142
Blog Entries: 4

Rep: Reputation: 121Reputation: 121
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.
 
Old 07-11-2005, 12:25 AM   #7
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,483

Original Poster
Rep: Reputation: 66
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?
 
Old 07-11-2005, 01:03 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,373

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
I think you shoulda copied and pasted it instead of retyping..! it's GdkEvent, not a GtkEvent.
 
Old 07-11-2005, 01:14 AM   #9
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,483

Original Poster
Rep: Reputation: 66
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
 
Old 07-11-2005, 01:25 AM   #10
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,483

Original Poster
Rep: Reputation: 66
Never mind i found it.

lol helps if i spell signal correctly.
 
Old 07-11-2005, 03:59 AM   #11
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,483

Original Poster
Rep: Reputation: 66
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GTK programming linetnew Programming 1 10-12-2005 11:34 AM
gtk programming sharapchi Programming 3 06-21-2005 02:22 PM
GTK programming geminigal Programming 1 06-02-2005 03:08 AM
Programming with GTK dfownz Programming 6 07-17-2004 01:50 PM
GTK and programming NSKL Programming 2 01-14-2003 03:30 PM


All times are GMT -5. The time now is 07:02 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration