GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Nov 23, 2014 7:58 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Problem w/ code example from Harlow book
PostPosted: Sat Feb 24, 2007 2:48 pm 
Offline

Joined: Sat Feb 24, 2007 2:21 pm
Posts: 3
Hello,

I am new to Gtk+ but have been using C++ for a few years.

I picked up the book, "Developing Linux Applications with GTK+ and GDK" by Eric Harlow and have been trying out some of the code examples from the book. In chapter 7 there is a Calculator example that compiles with no problem, but when running the application I try to add/subtract/multiply numbers nothing happens. In the book on pg. 136 he says

" ...when the user types in '=', the calculator looks up the previous command ('+'), the number saved in the buffer ('235'), and the number in the display '111'. The calculator must then perform addition of '235' and '111'. "

According to the author this application should add/subtract/... numbers but when I try it doesn't

The code examples for the book can be downloaded from this site

http://www.netbrain.com/~brain/book/

....this application "The GTK Calculator" is under Chapter 7

I'll add that when I compiled the code I got numerous warning about 'Implicit Declarations' for C language
functions like strcpy, strlen, atof and strcmp.

I would like to find out why this program will not perform arithmetic. Can someone help me out and point out where
the errors are?


Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 3:32 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Well, the first thing that you should know is that his book is based upon GTK+ 1.2. Most distributions come with GTK+ 2.10, which is the current release. Actually, almost every book on GTK+ is on version 1.2. Foundations of GTK+ Development, found at http://www.gtkbook.com, is the only book available on GTK+ 2.x. (In order to have full disclosure, I wrote this book.)

One of the reasons this may not be working is because of conflicts in libraries. It does not run on my system if I compile it against my version of GTK+. However, if I install GTK+ 1.2 alongside my version, it does compile and run.

As for your warnings, it is because he did not include <string.h> or <stdlib.h>. Compilers are stricter about this now, especially GCC. The application doesn't work because those functions cannot be found.

Lastly, his method of compiling is with gtk-config, but this is depreciated. You should be compiling with pkg-config, although the book will not cover it because the application did not exist when the book was released in 1999. I would recommend that in the future, when you buy a book, check the publication date. Even if you learn GTK+ from this book, you are going to be 5 years behind the game because there were an immense number of changes between GTK+ 1.2 and 2.0 (and beyond).[/url]

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 7:24 pm 
Offline

Joined: Sat Feb 24, 2007 2:21 pm
Posts: 3
Thank you very much Andrew,

I have a few books on Gtk+ but they are older like the Harlow book. I'll be sure to buy your book when released
so I can be educated on the most current Gtk+ 2 libraries.

I will look for a way to install Gtk+ 1.2 along with Gtk+ 2.0 so I can run these older applications and
at least make some use out of the books.

Actually, I did use GCC to compile the code and that is probably why I got the complaints. Thank you
for telling me about that.

Thanks again for responding to a beginner's post, I do appreciate it.

Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 10:51 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
I also have that Harlow book-- it has MANY MANY things that are obsolete. I only use it as a historical reference. Get Andrew's book... it's all up to date.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 11:04 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Micah's my TR, so he would know! :)

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 12:36 am 
Offline

Joined: Sat Feb 24, 2007 2:21 pm
Posts: 3
I installed Gtk 1.2 plus added <stdlibh> and <string.h> to Harlow's Calculator application, plus added pkg-congig
to the Makefile and it runs very well.

I just graduated from College with a CS degree but with never being hired it is hard to find entry level work. I was hoping to make my own calculator and base it loosely on Harlow's calculator and add it to sourceforge. I'm hoping to put an application onto a CVS so I can put it on my resume. If I design a calculator like Harlow's it would look like I am using deprecated library files. I'll be sure to get Andrew's book so I can make the app more current.

I have been looking for projects to join on sourceforge but I have not been getting answers from the emails I send out to the project managers. It's kind of like applying for a job, you know.

Next week I'll be doing a second interview for an entry job designing casino software, so that looks hopeful.

Thanks again Micah and Andrew, hope your having a nice weekend.


Regards,

Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 1:48 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Andrew's book has many, great example applications and snippets.

Good luck with the interview.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group